Currently when I try to insert new records I am getting an error:
[ERROR] 05/12/11_09:44:20.54 [org.hibernate.event.def.AbstractFlushingEventListener] – Could not synchronize database state with session
Db2 triggers to generate the ID need to remain in place to support legacy applications. How can I configure the hbm.xml to not generate the ID?
I’m not sure what version of Hibernate you are using, but Hibernate currently supports getting an ID that is generated from trigger via a special generator called select.
In short, you can add this generator to your ID column, and then reference a natural key you can use to retrieve the trigger generated ID as follows:
If your mapping already has a natural-key entry defined, then you shouldn’t even need to specify the
keyparam to the generator.One problem with this particular generator is that you can only use one entity property as the selection key for it. If you need to select via a composite key, then you’ll have to create your own generator for this purpose.
You could extend
org.hibernate.id.SelectGeneratoror one of it’s parents, and then implement the select via multiple columns that way. Then you simply replace theclassattribute of the above generator entry with the fully qualified class name of your new generator.