-->
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.  [ 1 post ] 
Author Message
 Post subject: eager loading and 1-many relationship
PostPosted: Fri Apr 29, 2011 8:23 am 
Newbie

Joined: Fri Apr 29, 2011 8:18 am
Posts: 1
0
down vote
favorite
I have a 1-many relationship between class A and class B, represented by a foreign key relation between two tables in the database. and I want hibernate to eagerly load the collection of Bs so that it can be traversed outside a session.

So I specify lazy="false" on both the one-to-many and many-to-one mapping entry.

B.hbm :
<many-to-one cascade="all" fetch="join" lazy="false"
class="A" name="...">
<column name="adgroup_id"/>
</many-to-one>

A.hbm
<list cascade="all" inverse="true" name="..." lazy="false" fetch="join">
<key column="adgroup_id" />
<one-to-many class="B" />
</list>


I notice that the sql executed by hibernate indeed returns the expected number of rows, but when I call

A.getBs(), I get too many elements. Indeed, since my ids in the database are auto-assigned, it seems to return n+1 elements where n is the currently highest id in the table of Bs.

What is going on here ?

I am using the Spring hibernate template btw, calling template.get(class,id) to return the A


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

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.