Results 1 to 6 of 6

Thread: Hi Everyone

  1. #1
    Join Date
    Jun 2007
    Posts
    6

    Default Hi Everyone

    I'm new to hibernate and spring.
    I've created DAOs that use HibernateTemplate and my services use proxy for transaction support.
    The problem that I'm facing is that if I want to set an entity member to Lazy fetch mode I get an error that the session is closed.
    What is the correct way for me to enable this feature?

    Thanks,
    Mike.

  2. #2
    Join Date
    Sep 2006
    Location
    UK
    Posts
    8,424

    Default

    If you search on the forum with the exception you are getting, you'll find lots of answers. OpenSessionInView Filter/Interceptor is one approach. Reattaching the entity to the Session to retrieve more data is one and eager loading is another.
    Last edited by karldmoore; Aug 27th, 2007 at 04:06 PM.
    Barracuda Networks SSL VPN Lead Developer
    http://pramatr.wordpress.com
    http://twitter.com/karldmoore
    http://www.linkedin.com/in/karldmoore
    Any postings are my own opinion, and should not be attributed to my employer or clients.

  3. #3
    Join Date
    Jun 2007
    Posts
    6

    Default Thanks karldmoore, one more option I read

    I did do a lot of searching.
    I would like to know if I can bother you with an option I found.
    Assuming that I do not want to put every member as EAGER and that I do not want to open a session on each request.
    Since I either get the entity members from a DAO (to which HibernateTemplate takes care of the session management issues) or a Service, wouldn't a wrapping of the relevant service method with transaction support (HibernateTransactionManager) be a correct solution?

    Hope my question is clear.
    Thanks,
    Mike.

  4. #4
    Join Date
    Sep 2006
    Location
    UK
    Posts
    8,424

    Default

    Yes, adding the transaction at the service layer would be a great idea. It's a pretty standard approach. Obviously the Session and therefore lazy loading is only possible for the lifetime of the transaction (if you aren't using OSIV), for other transactions you'd have to reattach the entity.
    Last edited by karldmoore; Aug 27th, 2007 at 04:06 PM.
    Barracuda Networks SSL VPN Lead Developer
    http://pramatr.wordpress.com
    http://twitter.com/karldmoore
    http://www.linkedin.com/in/karldmoore
    Any postings are my own opinion, and should not be attributed to my employer or clients.

  5. #5
    Join Date
    Jun 2007
    Posts
    6

    Default Thanks for the help karldmoore :)

    Thanks

    Mike

  6. #6
    Join Date
    Sep 2006
    Location
    UK
    Posts
    8,424

    Default

    Not a problem, glad to help! If you have any more questions just post back and I'll try to help.
    http://www.springframework.org/docs/...decl-explained
    http://www.martinfowler.com/eaaCatal...viceLayer.html
    Last edited by karldmoore; Aug 27th, 2007 at 04:06 PM.
    Barracuda Networks SSL VPN Lead Developer
    http://pramatr.wordpress.com
    http://twitter.com/karldmoore
    http://www.linkedin.com/in/karldmoore
    Any postings are my own opinion, and should not be attributed to my employer or clients.

Posting Permissions

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