Hi
I have a table in my database (oracle9) with a trigger for inserting rows: for each insert, it sets the primary key to a new value of some sequence (my_sequence).
In my hibernate mapping, i have something like this for my primary key:
Code:
...
<id name="id" column="ID" type="long">
<generator class="sequence">
<param name="sequence">my_sequence</param>
</generator>
</id>
...
So, when calling session.save(object), the following is happening (i suppose):
hibernate gets a new sequence number, assigns it to the 'object' parameter and performs an insert... that insert is triggered by the database, so the trigger gets a new sequence number and assigns it as the new primary key of the row-to-be-inserted. Of course:
1. my sequence number is increased by two for each insert
2. session.save returns me the wrong sequence number, i.e. first the sequence number
3. the newly persisted object has the wrong primary key
My question: can i do something about it? (it is impossible to remove the trigger!).
Kind regards
Pieter Vandepitte[/code]