-->
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: Can't understand how object are loaded
PostPosted: Tue Aug 29, 2006 5:56 am 
Beginner
Beginner

Joined: Mon Dec 26, 2005 4:55 pm
Posts: 28
Hi,

I do not know if I am asking a stupid question, but how can I load an object without loading any other object referenced from it?

I have read the Hibernate documentation. In the documentation it talks about lazy initialization. I am setting (from xDoclet) lazy="true" in the @hibernate.list, however I still have all objects in that collection loaded.

Please can anyone help me out, I really can not understand how this works, and the more I read the more I get confused. I do not mind if I have to start using the latest version of Hibernat, just some comments to make me understand

Thanks in advance for any comments,

Regards,
Sim085


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 29, 2006 8:34 am 
Regular
Regular

Joined: Fri May 12, 2006 4:05 am
Posts: 106
Hi,

here's some remarks about how this lazy-loading-thing works:
Suppose you got an A-object containing a reference to a B-object.
When loading A (and lazy=true) hibernate won't access the database to retrieve the B-object, but it will replace it by an appropriate proxy-object exposing an identical interface. Upon acessing any of B's methods or fields the proxy will automatically load and instatiate the B-object, so you won't realize you haven't been working on the real object (unless your hibernate-session has ended before accessing B: then the loading will fail with an exception).

Here's some ways you can check, if the B-object has already been loaded when loading A. Before accessing B you could:
1.) Check the sql-statements hibernate generated by setting show_sql=true in your configuration-file
2.) check A.getB().getClass() - you should find the hibernate-proxy instead of B's class
3.) close your hibernate-session, then access B and watch the exception ;-)


Greets

piet


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 30, 2006 10:37 am 
Beginner
Beginner

Joined: Mon Dec 26, 2005 4:55 pm
Posts: 28
Thanks piet :)

That explanation was very good :) I had read this in the Hibernate Documentation as well, however the proxy thing was new to me because the Hibernate Documentation I read was of version 3.0.

Did this proxy thing come after the 3.0 (that is only available in the 3.1.3)?

My problems came because I configure my objects using xDoclet, and xDoclet does not allow the options 'proxy' or 'no-proxy', but only 'true' or 'false'. I further searched this on these forums and found that this is a limitiation of xDoclet. Tried searching for a new version but did not find one.

Also, if B is loaded as a proxy in A, would I be able to get an instace of B after the session is closed? (like opening the session again) without having to reload A?

thanks piet, the proxy thing was really helpfull :)

regards,
Sim085


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.