-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Hibernate3 does not lazy load by default
PostPosted: Tue Mar 08, 2011 7:25 am 
Newbie

Joined: Tue Mar 08, 2011 7:07 am
Posts: 1
Hi,

We have used Hibernate 3 with annotation based mapping. Hibernate by default does Lazy Loading on all associations. We have implemented a one-to-many relationship through a join table. The problem here is the associations are always eagerly loaded until I explicitly set fetch=FetchType.LAZY ? Is this required ? Shouldn't hibernate load it lazily by default ?

Code:

public class User{
@OneToMany
    @JoinTable(name = "user_system", joinColumns = {
            @JoinColumn(name = "user_id", unique = true)
    },
            inverseJoinColumns = {
                    @JoinColumn(name = "system_id")
            }
    )
    private List<System> systems = new ArrayList<System>();
}

public class System{
@ManyToOne
    @JoinTable(name = "user_system",
            joinColumns = {@JoinColumn(name = "system_id", unique = true)},
            inverseJoinColumns = {@JoinColumn(name = "user_id")}
    )
    private User user;
}



Top
 Profile  
 
 Post subject: Re: Hibernate3 does not lazy load by default
PostPosted: Tue Mar 08, 2011 9:46 am 
Expert
Expert

Joined: Thu Jan 08, 2009 6:16 am
Posts: 661
Location: Germany
Quote:
@OneToMany and @ManyToMany associations are defaulted to LAZY and @OneToOne and @ManyToOne are defaulted to EAGER.

from http://docs.jboss.org/hibernate/stable/annotations/reference/en/html_single/#entity-mapping-association

_________________
-----------------
Need advanced help? http://www.viada.eu


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.