Results 1 to 2 of 2

Thread: Weird Transaction problem

  1. #1
    Join Date
    May 2006
    Posts
    1

    Default Weird Transaction problem

    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

  2. #2
    Join Date
    Aug 2006
    Location
    Arequipa-Peru / South America
    Posts
    2,796

    Default

    Hello

    I get LazyInitialization exception because of closed session
    Such LazyInitializationException belong to Hibernate.

    However, if I change Method B to PROPAGATION_SUPPORTS, there are no exceptions and I am able to access the child objects.
    Interesting but could be reasonable.

    What is the difference between PROPAGATION_REQUIRED and PROPAGATION_SUPPORTS?
    Read the follow Propagation carefully, there you have a expanded explanation for each option.

    The LazyInitializationException is related with the cascade attribute of the @OneToMany , such is not related with Spring.
    - Manuel Jordan

    Kill Your Pride, Share Your Knowledge With All
    The Fear Of The LORD Is The Beginning Of Knowledge, But Fools Despise Wisdom And Discipline. Proverbs 1:7

    Blog


    Technical Reviewer of Apress

    • Pro SpringSource dm Server
    • Spring Enterprise Recipes: A Problem-Solution Approach
    • Spring Recipes: A Problem-Solution Approach, 2nd Edition
    • Pro Spring Integration
    • Pro Spring Batch
    • Pro Spring 3
    • Pro Spring MVC: With Web Flow
    • Pro Spring Security

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •