-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Complex event case - PreInsertEvent, ID, object states
PostPosted: Mon Oct 08, 2012 3:06 pm 
Newbie

Joined: Thu Mar 13, 2008 11:18 pm
Posts: 2
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


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.