-->
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.  [ 4 posts ] 
Author Message
 Post subject: n+1 selects in birectional one to one association
PostPosted: Mon Mar 24, 2008 3:53 pm 
Newbie

Joined: Mon Mar 24, 2008 3:49 pm
Posts: 3
I have a class A which has an object of Type B.A is associated with B with a one to one mapping and the association is bi-directional.In table A I have the id of B say for eg "b_Id" The problem is that when I try to Query using HQL "from A where some condition....",hibernate is generating sql "select * from A where b_Id =?" multiple times.I have joined A with B using left join fetch.Even then it gives n+1 selects.Can anybody help me on this to find an alternative


Top
 Profile  
 
 Post subject: one-to-one relationship dilemma
PostPosted: Mon Mar 24, 2008 11:48 pm 
Newbie

Joined: Wed Mar 28, 2007 1:05 am
Posts: 8
Hi,

You will find lot of information on one-to-one relation if you search hibernate forum with one-to-one as key. For you reference one of the good forum i have found is

http://www.hibernate.org/162.html

It explains one-to-one details. Summary from that article is you can use contraint=true attribute in your one-to-one relationship if you know A will always be associated with B. i.e. its true one-to-one not one-to zero or one.

Cheers,
Deepak


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 25, 2008 9:28 am 
Newbie

Joined: Mon Mar 24, 2008 3:49 pm
Posts: 3
My case is one to zero or one mapping


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 03, 2008 6:54 am 
Newbie

Joined: Wed Mar 28, 2007 1:05 am
Posts: 8
Hi,

in that case u wont be able to use contraint = true. one thing you can do is either treat it like one-to-many or Inheritence with proxy.


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