Results 1 to 3 of 3

Thread: Hibernate and lazy load

  1. #1

    Default Hibernate and lazy load

    Sorry about the repost, I posted to wrong forum previously.

    Hello,

    Here is my situation. I have three classes A, B, and C. Class A has a collection of B and B has a collection of C. I'm using Hibernate for persistence. I have mapped the collections as lazy - since most of them I don't need to retrieve the entire graph. I have DAO classes for each A, B, and C. Each DAO classes extends HibernateDaoSupport.

    My problem is, for one case I need to retrieve the entire graph. After rereading the the docs and the forums, I realize that HibernateDaoSupport opens and closes the session for me and to avoid a LazyInitializationException I need to reattach the object to a session. Fair enough.

    My question, is would it be a good idea to create an Intercepter on A.getB() and B.getC() that would make a call to Hibernate.initialize() ?

    If not, or if there is a better idea, could someone direct me to sample code? I've looked at the Spring samples but there does not appear to be an example of using Hibernate with lazy collections.

    Thanks.

  2. #2
    Join Date
    Aug 2004
    Location
    San Mateo, CA
    Posts
    1,265

    Default

    You could explicitly touch the relationship methods within your DAO or the enclosing transaction from service layer. Or you could use a fetch join. I don't much like the interceptor approach: seems a bit too much magic vs these simpler techniques.
    Rod Johnson - GM, SpringSource Division, VMware
    http://www.springsource.com
    Spring From the Source

  3. #3
    Join Date
    Apr 2005
    Location
    Fairfax, VA
    Posts
    1

    Default did you get this figured out?

    I'm a new user to everything, having a similar issue with A has collection of B, B has collection of C, and getting the lazy loading to work when you want to eagerly fetch in one instance. I'm not sure how to initialize the collections using the HibernateDAOSupport getHibernateTemplate calls. I originally do a find, then I want to initialize the collections associtated to the object I found. Any help would be appreciated, I have read the documentation and I am still lost. Thanks.

Similar Threads

  1. Hibernate and lazy load
    By mfuller in forum Architecture
    Replies: 20
    Last Post: Apr 28th, 2009, 11:09 AM
  2. Replies: 2
    Last Post: Dec 8th, 2005, 09:00 AM
  3. how to use hibernate lazy loading with spring transaction
    By tanmoy.chakraborty in forum Data
    Replies: 1
    Last Post: Oct 11th, 2005, 02:07 AM
  4. Hibernate and Lazy Loading.
    By cmrudd in forum Data
    Replies: 1
    Last Post: Oct 3rd, 2005, 03:58 AM
  5. Spring, JSF, Hibernate & Lazy Collections
    By e.medina.m in forum Data
    Replies: 3
    Last Post: Mar 9th, 2005, 03:28 AM

Posting Permissions

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