我有一个表,其索引由使用序列的触发器自动填充(Oracle 数据库)
CREATE TABLE A
(
IDS NUMBER(10) NOT NULL
)
CREATE OR REPLACE TRIGGER A_TRG
BEFORE INSERT
ON A REFERENCING NEW AS New OLD AS Old
FOR EACH ROW
BEGIN
:new.IDS := A_SEQ.nextval;
END A_TRG;
/
我有一个匹配的 Java 类:
Class A {
@Id
@SequenceGenerator(name = "aSequence", sequenceName = "A_SEQ", allocationSize = 1)
@GeneratedValue(generator = "aSequence", strategy = GenerationType.SEQUENCE)
@Column(name = "IDS")
Long id;
...
}
当我尝试像这样持久化 A 的实例时:
EntityTransaction transaction = entityManager.getTransaction();
transaction.begin();
A a = new A();
Long id = getHibernateTemplate().save(a);
transaction.commit();
我遇到了这个问题:
保存调用返回的代码中的 ID = "X"
数据库中的 ID = "X+1"
有没有办法设置 Hibernate 让数据库触发器创建 ID?
谢谢