This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft on-line!
See this thread for details.
The moose likes Object Relational Mapping and the fly likes Hibernate returns List with NULL Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Reply locked New topic
Author

Hibernate returns List with NULL

Jazzy Sanchez
Ranch Hand

Joined: Apr 02, 2006
Posts: 35
Hi. I am getting a result from hibernate but the List object has null values on it.

Any ideas of the reason?


Thanks!
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17249
    
    6

It is lazy loaded?

Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
Jazzy Sanchez
Ranch Hand

Joined: Apr 02, 2006
Posts: 35
Yes it is.
kwame Iwegbue
Ranch Hand

Joined: Sep 02, 2000
Posts: 197
In that case you can initialize the List with a call like myList.size() or something like that. That would usually load the Collection from the database. Or, you can change the class mapping to make it eager loaded. With Annotations, you would write something like this:



Who dares, wins! (SAS motto)
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17249
    
    6

I would probably not set the relationship to eager in the mapping, but set fetch modes in your Queries so that you can eager fetch what you need for the particular use case you are working on. But yes, when you need that list filled you can touch the list so to speak, or in your query that loads the data set that to fetch eager. But it must be within the context of a session or entityManager.

Mark
Jazzy Sanchez
Ranch Hand

Joined: Apr 02, 2006
Posts: 35
I am sorry. It is NOT Lazy Loading. It is not recommended to have a eager loading?
Ann-Marie Russell
Greenhorn

Joined: Sep 29, 2004
Posts: 6
I had the same issue and just caught what my mistake was. I don't know if you're using the index column property or not, but I was. And with a list this was putting the objects in the precise index from the database...since my values were 1, 2, 3 the 0 index was null.

not sure if that helps you out or not.

felt pretty foolish when I figured it out.


amr04
Erap Estrada
Ranch Hand

Joined: Nov 08, 2006
Posts: 92
I have the same problem. I removed the index property but there's an xml error.

Guys please help.

Thanks!


SCJP with 98% by...
Erap Estrada
Ranch Hand

Joined: Nov 08, 2006
Posts: 92
here's the mapping in parent

<list name="reviews">
<key column="member_id"/>
<index column="review_id"/>
<one-to-many class="Review" />
</list>

Here`s the mapping in child

<many-to-one
name="member"
class="Member"
column="member_id" not-null="true"/>
[ October 02, 2007: Message edited by: Erap Estrada ]
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17249
    
    6

Erap, I am sorry, I am not sure what your issue is right now, because of it being posted in the context of this older thread.

Can you create a new Thread for your issue and please post the problem you are having?

Thanks

Mark
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Hibernate returns List with NULL
 
Similar Threads
How to NOT fetch a collection?
When Session Closed Data Will be Lost in Hibernate
performance of hibernate?
Update Single value in a row
Hibernate returning List with NULL values