Mar 2nd, 2011, 02:43 PM
LIE Errors After Exception Thrown in a Hibernate Interceptor
I have a Hibernate interceptor that prevents a transaction from being completed upon certain conditions. The interceptor throws an exception on preFlush that leads to the transaction being rolled back. I am using @Transactional annotations on my services so this should happen automatically. I then have FlowExecutionExceptionHandler that catches these exceptions, adds the exception message to the message context, and the forces a flow execution redirect. After this happens, I begin to see LazyInitializationExceptions. I have been trying to determine why this may happen and appreciate any input. I had put breakpoints on the close method of the EntityManager, but that is not being called. Before the error, the objects are able to be lazily loaded.
Webflow 2.2.1, JSF, Richfaces 3.3.3, Spring 3.0.5
Mar 2nd, 2011, 07:30 PM
So after reading this:
"When the transaction ends, either through commit or roll back, the "current" Session is closed automatically."
This means that my session will always be closed. Looking at the code in the JpaTransactionManager.doRollback(DefaultTransactio nStatus status) method, it would seem this is inevitable. This is called from the TransactionInterceptor via the call to completeTransactionAfterThrowing in the invoke method.
Can someone help me understand whether or not there is a way to prevent the clearing/closing of the session or if I need to re-associate my objects with the session? It seems that not clearing the session might leave it in an inconsistent state. Any insight would be appreciated.
Last edited by julian; Mar 3rd, 2011 at 12:00 AM.