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.  [ 5 posts ] 
Author Message
 Post subject: One-to-many returns null objects when records do not exist
PostPosted: Mon Nov 17, 2008 4:59 pm 
Newbie

Joined: Tue Jul 15, 2008 5:39 pm
Posts: 5
Location: Springfield, MO
I have a problem where a child collection is being populated with 166 null objects when the database only has one.

I have one parent record with one child. When the parent is loaded it load 166 child records and the last one is populate.

I can figure out why there are so many children. The sql statments are returning the correct record but it seems that the child query is being executed multiple times.

Any suggestions would be greatly appreciated. Here is my mapping of the child collection.

<list name="CurrentDosageDetails" inverse="true" lazy="false">
<key column="MedDosHdrId" />
<index column="MedDosDtlId" type="Int32" />
<one-to-many class="MedicationDosageDetail, Entities" />
</list>


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 18, 2008 3:57 am 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
What does the index column contain ? 166 ? Then the object is inserted at index 166 in the list and the items from 0 to 165 are filled with null.

_________________
--Wolfgang


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 18, 2008 12:11 pm 
Newbie

Joined: Tue Jul 15, 2008 5:39 pm
Posts: 5
Location: Springfield, MO
Is there a way to turn that off or must I use a SET to get just the records I have in my database?

Also is there an example of where you want a collection populated with nulls when no objects exist?

Thanks for the reply.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 18, 2008 12:30 pm 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
Quote:
Is there a way to turn that off or must I use a SET to get just the records I have in my database?


No switch. You can use a bag or set. The main question is, what your "index" is for. If it's not really necessary for positioning/ordering the elements, the you can safely switch to a bag or set.

Quote:
Also is there an example of where you want a collection populated with nulls when no objects exist?


I admit it looks a bit strange on the first view. But when you think a bit about it, it's the only logical way. Either that column is an index for your collection than hibernate has to put the element at this position or it's not an index and then your "list" isn't really a list (from a semantical point of view).

_________________
--Wolfgang


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 19, 2008 2:36 pm 
Newbie

Joined: Tue Jul 15, 2008 5:39 pm
Posts: 5
Location: Springfield, MO
Thanks. That was exactly what I needed.


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