-->
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.  [ 2 posts ] 
Author Message
 Post subject: Custom IdentifierGenerator causing infinite recursion
PostPosted: Tue Nov 22, 2005 7:17 pm 
Expert
Expert

Joined: Fri Oct 28, 2005 5:38 pm
Posts: 390
Location: Cedarburg, WI
I created a custom IdentifierGenerator which verifies that the ID it generates does not yet exist in the database, before returning it (if it does, it tries generating a different one.)

However, when the query to verify the (non)existence of the newly generated ID is issued, it automatically causes another Flush() to occur. The 2nd Flush() tries to generate keys for all transient entities to be saved, causing infinite recursion. :(

I don't see anything in the documentation (even in Hibernate's documentation) that says you're not supposed to use the session passed to IIdentifierGenerator.Generate() to query anything. (What would you use it for otherwise?)

How can this be done? Should I be verifying the new ID in a different session?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 22, 2005 7:39 pm 
Expert
Expert

Joined: Fri Oct 28, 2005 5:38 pm
Posts: 390
Location: Cedarburg, WI
OK, there's a property on the session called FlushMode, which you can temporarily set to FlushMode.Never. That did the trick. I could have sworn I had read about this property recently, but couldn't find it before making the original post :oops:

Still, there should be some kind of warning or "gotcha" mentioned in the documentation for this, especially since there are similar warnings about not invoking the session or otherwise causing lazy-loading to occur from an interceptor callback.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.