Hello,
I have a table with an index auto filled by a trigger that use a sequence (Oracle database):
Code:
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;
/
I have a matching Java class:
Code:
Class A {
@Id
@SequenceGenerator(name = "aSequence", sequenceName = "A_SEQ", allocationSize = 1)
@GeneratedValue(generator = "aSequence", strategy = GenerationType.SEQUENCE)
@Column(name = "IDS")
Long id;
...
}
When I try to persist an instance of A like this:
Code:
EntityTransaction transaction = entityManager.getTransaction();
transaction.begin();
A a = new A();
Long id = getHibernateTemplate().save(a);
transaction.commit();
I get this problem:
- ID in code returned by the save call = "X"
- ID in database = "X+1"
Is there a way to setup Hibernate to let the database trigger create the ID ?
Thanks