Hi,
I am facing a weird transaction problem with Spring and Hibernate. Here are the transaction settings:
Method A - (PROPAGATION_REQUIRED, readOnly) Method B - (PROPAGATION_REQUIRED, readOnly) - returns objects( Object A, which contains collection of child objects) Method C - (PROPAGATION_REQUIRED, readOnly)
Method A is the main method that queries for a set of objects using Method B, iterates through the objects and any associations and may use Method C for any other processing.
The problem is that all methods work perfectly OK, but when I try to access child objects of the objects returned by Method B, I get LazyInitialization exception because of closed session. However, if I change Method B to PROPAGATION_SUPPORTS, there are no exceptions and I am able to access the child objects.
What is the difference between PROPAGATION_REQUIRED and PROPAGATION_SUPPORTS? I enabled debug on the transactions and see that Method A and B are participating in a transaction with both REQUIRED and SUPPORTS case. However, with REQUIRED, a new session is created for Method B and is closed when Method B exits. While with SUPPORTS, the session is not closed.
I really appreciate if someone can help me out with this. If there is any other way to do it so that I dont get Lazy Exceptions, also would be greatly appreciated.
Thanks
|