-->
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: Problem with Interceptor example in Hibernate book
PostPosted: Thu Jul 23, 2009 6:48 am 
Newbie

Joined: Mon Jul 20, 2009 7:11 am
Posts: 6
Hi:

I have extended the Interceptor example in the Java persistence with Hibernate book to force a persistent object to be refreshed when it is created (the refreshed object contains a one-to-many collection, and a database trigger on insert into the one table inserts into the database table on the many side).

I have followed the same basic pattern as in the book:
Set the interceptor when each session is created
Store the session in a local variable associated with the session
In postFlush, create a new session using the same connection as the original session
Call refresh on the item being saved to the database


This works fine, except that if I include a call to close the temporary session in my Interceptor, then this seems to close the original session: if I access the newly refreshed object, I get a LazyInitializationException indicating that the session has been closed. Perhaps this is because closing the temporary session closes the JDBC connection being used by the original session, which puts that session into a closed state, I'm not sure.

Is this behavior to be expected? Am I doing anything dangerous by not closing the temporary session in the interceptor?

Thanks for any insights.


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.