I have a bit of a problem, I can create a person object fine with NHibernate and have an associated ID with that object which is collected by the ID Generator via a native "sequence" in the DB.
See:
<id name="Id" type="Int32" column="PERSON_ID">
<generator class="native">
<param name="sequence">PER_SEQ</param>
</generator>
</id>
I can save and commit the object to the DB, which works fine.
The problem is that the table has a trigger associated with it that increments the sequence each time a new row is inserted.
So my object gets the next sequence ID, say 5.
It assigns it to the object. Fine.
It saves and commits the object.
The DB fires a trigger, which increments the sequence, giving the actual entry an ID of 6 in the database.
My object, non-the-wiser thinks that it is still 5, but the DB has it down as 6.
Also as the sequence is being called twice, its causing the seq to jump by 2 for each insert.
Database ID's are going...2,4,6,8,10
and my objects think they are ID...1,3,5,7,9
Theres no chance I can have the trigger amended or removed as there are too many other processes and applications that rely on it.
According to some of the DBA's, I need to change my SQL statement to include "returning into" to retrieve the ID assigned on insert by the trigger.
Despite crawling the forums I've only found one entry with a similar issue:
http://forum.hibernate.org/viewtopic.php?t=980364
This is my exact same problem, and there seems to be a solution, but is problem this now resolved with NHibernate?
If so, how can I change my ID generator to expect a value returned from the DB on Insert?
I'm a bit of an Nhibernate newb, so I don't full understand the solution mentioned in:
http://forum.hibernate.org/viewtopic.php?t=980364
or how to modify the source code for NHibernate myself to implement it.
Any help would be greatly appreciate! Thanks