This week's book giveaway is in the Design forum.
We're giving away four copies of Design for the Mind and have Victor S. Yocco on-line!
See this thread for details.
Win a copy of Design for the Mind this week in the Design forum!
    Bookmark Topic Watch Topic
  • New Topic

Hibernate returns List with NULL

 
Jazzy Sanchez
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Report post to moderator
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
Posts: 17278
6
IntelliJ IDE Mac Spring
 
Jazzy Sanchez
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Report post to moderator
Yes it is.
 
kwame Iwegbue
Ranch Hand
Posts: 197
  • Mark post as helpful
  • send pies
  • Report post to moderator
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:

 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Report post to moderator
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
Posts: 35
  • Mark post as helpful
  • send pies
  • Report post to moderator
I am sorry. It is NOT Lazy Loading. It is not recommended to have a eager loading?
 
Ann-Marie Russell
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Report post to moderator
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.
 
Erap Estrada
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
  • Report post to moderator
I have the same problem. I removed the index property but there's an xml error.

Guys please help.

Thanks!
 
Erap Estrada
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
  • Report post to moderator
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
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Report post to moderator
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
 
    Bookmark Topic Watch Topic
  • New Topic