Hello,
I am trying to implement the following:
- Object A is saved (through Session.save()) - Related object B is created - ID of the object B is saved in object A [unsolved] - ID of the object A is saved in object B [unsolved]
I want to automate the process because object A is abstract and spans multiple concrete types.
The obvious attempt may be to respond to PreInsertEvent Hibernate Event. In the handler of PreInsertEvent in the response of saving the object A I can create the object B which is properly persisted. However because the ID of the object A is not established during the PreInsertEvent - it is generated by the underlying DB (@GeneratedValue(strategy = GenerationType.IDENTITY) - the exchange of IDs must be handled somewhere else. PostInsertEvent is already too late, modifications to the object state is not persisted.
What would be the best approach to exchange and save the IDs in A and B?
Thanks! Hynek
|