-->
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: List contains null-pointers
PostPosted: Tue Apr 25, 2006 4:21 pm 
Newbie

Joined: Tue Apr 25, 2006 4:00 pm
Posts: 1
I haven't got much experience with Hibernate, I just started with it last weekend for a school project. I already managed to do some things but there's just one thing I can't get to work. One of the classes I use contains a list (it actually contains 2 collections). When Hibernate loads those lists, the lists contain all necessary objects, but they also contain a lot of null-pointers. Is this normal behavior?

I use the following code to load the lists:

<list name="competenties" lazy="true" inverse="true" cascade="all">
<key column="comCompRooster"/>
<index column="comNr"/>
<one-to-many class="Competentie"/>
</list>

<list name="groepen" lazy="true" inverse="true" cascade="all">
<key column="grpCompetentieRooster"/>
<index column="grpNr"/>
<one-to-many class="Groep"/>
</list>

Hopefully someone can help me with this.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 25, 2006 5:19 pm 
Expert
Expert

Joined: Fri Aug 19, 2005 2:11 pm
Posts: 628
Location: Cincinnati
if you have any inconsistencies in the contuinity of your index column, hibernate will insert nulls to fill those voids.

I don't know where that sentence came from but I'll explain it better. If for a specific collection, in your db you have the index column with values

0,1,2,3,4,5,6 you will get a list back with no nulls

if, however, your index column has the values
1,2,3,4,6

you will get a list back with null values in the '0' spot and the '5' spot.

Hibernate expects it to start at 0 and have a continuous set of integers

_________________
Chris

If you were at work doing this voluntarily, imagine what you'd want to see to answer a question.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 26, 2006 2:44 am 
Beginner
Beginner

Joined: Wed Apr 05, 2006 3:19 pm
Posts: 43
I had the same problem. I used a Set instead. It works just fine now. The only thing I can't do right now, is list.get(index). But then you could always do a session.createQuery("select * from table where id = ?");

_________________
Don't forget to rate my post if it helped. :)


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.