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.
|