aspose file tools*
The moose likes Object Relational Mapping and the fly likes List that contains null values Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "List that contains null values" Watch "List that contains null values" New topic
Author

List that contains null values

Erap Estrada
Ranch Hand

Joined: Nov 08, 2006
Posts: 92
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.


SCJP with 98% by...
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17249
    
    6

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


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

Joined: Nov 08, 2006
Posts: 92
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

Joined: Dec 11, 2006
Posts: 364
Originally posted by Erap Estrada:
I already set inverse to true for both.


Just one, please
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17249
    
    6

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

Joined: Nov 08, 2006
Posts: 92
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

Joined: Nov 08, 2006
Posts: 92
Set resolved the issue. Thank you so much!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: List that contains null values
 
Similar Threads
Hibernate: Does not refresh after deletion
Hibernate collection mapping
org.hibernate. NonUniqueObjectException
mapping a list based on a discriminator
Hibernate returns List with NULL