-->
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.  [ 8 posts ] 
Author Message
 Post subject: lazy loading in one-to-one mapping
PostPosted: Thu Jul 08, 2004 8:59 pm 
Beginner
Beginner

Joined: Wed Jun 09, 2004 2:49 pm
Posts: 25
I have two class that have one-to-one relationship.
I found whever I load an object of first class from Database,
it always do anto-join. I really want lazy loading of the object of the
second class, how to do that?
Speficying proxy on the second class is not preventing auto-join.

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 09, 2004 4:53 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
http://www.hibernate.org/162.html should help you


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 09, 2004 12:57 pm 
Beginner
Beginner

Joined: Wed Jun 09, 2004 2:49 pm
Posts: 25
So my understanding is:
in case of one-to-one mapping and constrained is false.
I may be more efficient to load the object of the second class mannually?

Jim


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 30, 2008 8:01 pm 
Regular
Regular

Joined: Fri Oct 05, 2007 3:22 am
Posts: 69
I have this problem as well is there a way to get the lazy loading on a one to one where I can't use optional = false using annotations.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 30, 2008 10:42 pm 
Regular
Regular

Joined: Fri Oct 05, 2007 3:22 am
Posts: 69
I have also just tried doing instrumentation and adding the

@OneToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY )
@PrimaryKeyJoinColumn
@org.hibernate.annotations.LazyToOne( org.hibernate.annotations.LazyToOneOption.NO_PROXY )

annotations. The entity is still not lazy loaded.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 31, 2008 4:33 pm 
Expert
Expert

Joined: Tue May 13, 2008 3:42 pm
Posts: 919
Location: Toronto & Ajax Ontario www.hibernatemadeeasy.com
Code:
<one-to-one constrained="true" outer-join="false" class="Foo"/>


That always seemed to work in a mappings file. I wonder why the annotations equivalent doesn't do lazy loading?

_________________
Cameron McKenzie - Author of "Hibernate Made Easy" and "What is WebSphere?"
http://www.TheBookOnHibernate.com Check out my 'easy to follow' Hibernate & JPA Tutorials


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 31, 2008 5:57 pm 
Regular
Regular

Joined: Fri Oct 05, 2007 3:22 am
Posts: 69
Thanks for the response, this is really bad, I mean with lazy loading my queries go from 5 minutes to 8 seconds.

The problem is the OneToOne is not optional. If I could somehow trap the EntityNotFoundException and return null this would be fine as well but there is a JBoss transaction interceptor that is throwing it from the accessor.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 31, 2008 7:11 pm 
Regular
Regular

Joined: Fri Oct 05, 2007 3:22 am
Posts: 69
Ah I had another versionf of the cglib.jar file in my path. Removing and doing instrumentation again resolved it phew.


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