-->
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.  [ 3 posts ] 
Author Message
 Post subject: lazy proxy fetching for single-valued associations?
PostPosted: Fri May 16, 2008 10:59 am 
Newbie

Joined: Wed Feb 14, 2007 5:38 am
Posts: 6
Hibernate version: 3.2.6

In the reference documentation it says:

"By default, Hibernate3 uses lazy select fetching for collections and lazy proxy fetching for single-valued associations"

Has the fetching strategy for single-valued associations changed in version 3.2.x?

I use the following example:


Code:
@Entity
public class Customer {
    @Id 
    @GeneratedValue
    private int id;
    private String name;
    @OneToMany
    @JoinColumn (name="clientid")
    private Collection<CreditCard> creditCards = new ArrayList();
    @OneToOne
    @JoinColumn (name="addressid")
    private Address address;


Then when I execute the following code in the debugger:

Code:
java.util.List list = session.createQuery("from Customer").list();


or

Code:
Customer client = (Customer) session.get(Customer.class, id);


in both cases the address field is not a proxy, but the address object contains all address information from the database. So the address is eager loaded.
I know that this is the default behaviour for JPA, but is this also the default behaviour of hibernate?
If yes, then the reference documentation is not correct.
If no, then why do I get this behaviour in my example program?

Thanks,

Rene


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 16, 2008 12:59 pm 
Newbie

Joined: Wed May 14, 2008 3:45 pm
Posts: 8
In order to enable lazy loading in the one to one mapping you need to tell hibernate that the entity in the other end of association always exist. So that when the hiberante actually initializes the proxy it won't get "object not found" kind of excpetion. In hibernate mapping you do this by specifying contrained="true".


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 20, 2008 4:27 am 
Newbie

Joined: Wed Feb 14, 2007 5:38 am
Posts: 6
Well, my question was actually:

What is the default fetching behaviour of Hibernate for single-valued associations (One-to-one or Many-to-one)?

I thought that Hibernate was alway's lazy, but from the example in my previous post, it shows that the one-to-one association is eagerly loaded.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.