-->
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.  [ 6 posts ] 
Author Message
 Post subject: Event Listeners and Identities
PostPosted: Thu Nov 10, 2005 4:19 pm 
Newbie

Joined: Tue Aug 30, 2005 4:43 pm
Posts: 8
Within the event listener/interceptor model is there an event that occurs during the save process where you can get access to values created by the database (identity) during the save? I've tried post-insert and save-update but both events show the identity values as null. Any help would be appreciated.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 11, 2005 1:19 pm 
Newbie

Joined: Fri Oct 14, 2005 11:43 am
Posts: 18
The PostInsertEventListener will give you this.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 11, 2005 1:24 pm 
Newbie

Joined: Fri Oct 14, 2005 11:43 am
Posts: 18
Strange that you don't see it on the post-insert. That event is giving me the correct id here (3.1rc2). I'm using native generation of "long" ids against a mysql database.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 11, 2005 1:29 pm 
Newbie

Joined: Tue Aug 30, 2005 4:43 pm
Posts: 8
Hmm... I do see it under the id property of PostInsertEvent object, but for some reason it is not under entity object (still null). Thanks for your help. Now my next question is can I potentially rollback (veto) the transaction at this point? Basically I want to try an operation at this level once I know what the database generated key is. If by chance this operation has a problem, I want to force a rollback of everything.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 14, 2005 8:02 am 
Newbie

Joined: Fri Oct 14, 2005 11:43 am
Posts: 18
I've not tried this out, but looking at the code I'd say that throwing any exception from an event handler should do what you want.

Another possibility would be to get hold of the current transaction, and call rollback on it. Can't immediately see how to get the current transaction, but there must be a way...


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 28, 2005 5:12 am 
Newbie

Joined: Wed Mar 03, 2004 10:19 am
Posts: 11
Location: Netherlands
Does anyone know how to get the current transaction? The session is not passed in the PostInsertEvent, as it is in PreInsertEvent?

Frido


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

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.