Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

List that contains null values

 
Erap Estrada
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there. I am retrieving a List through Hibernate. The problem is the returned List contains null values. So when I iterate through it, I also ran to those null values. Objects are apart from each other in the List.

Here's the mapping for the parent class Member
<list name="reviews">
<key column="member_id"/>
<index column="review_id"/>
<one-to-many class="Review" />
</list>

Here's the mapping for the child class Reviews
<many-to-one
name="member"
class="Member"
column="member_id" not-null="true"/>

Basically, each Member has multiple reviews.
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First, based on your mapping, Hibernate does not know that those two mappings are mapping the same relationship. You need an inverse="true" in there.

Mark
 
Erap Estrada
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I already set inverse to true for both. Any more ideas what causing this?

I read somewhere that causing it could be the index column but did not specify how to resolve it.

I am starting to feel hibernate is complicated. All I want is "Member has multiple Reviews" and a "Review has a Member".

Thanks in advance!
[ October 03, 2007: Message edited by: Erap Estrada ]
 
Edvins Reisons
Ranch Hand
Posts: 364
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Erap Estrada:
I already set inverse to true for both.


Just one, please
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Erap Estrada:
I already set inverse to true for both. Any more ideas what causing this?

I read somewhere that causing it could be the index column but did not specify how to resolve it.

I am starting to feel hibernate is complicated. All I want is "Member has multiple Reviews" and a "Review has a Member".

Thanks in advance!

[ October 03, 2007: Message edited by: Erap Estrada ]


Hibernate has a good sized learning curve because it is extremely feature rich, and allows you to really set things up exactly how you want it, and with features to make it really fast.

With that in mind, for a simple one to many, try just using a Set first instead of trying a List, since the index-column is there because Lists needing an order.

Try a Set and see how that works for you.

Mark
 
Erap Estrada
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I apologize if I sound desperate. I temporarily resolve it by creating a utility class to clear the null values in the List.

But I will try to use Set instead and I'll post the result of it here.

Again, thank you so much guys.
 
Erap Estrada
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Set resolved the issue. Thank you so much!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic