-->
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.  [ 4 posts ] 
Author Message
 Post subject: Having problem in Hibernate one-to-many association
PostPosted: Fri Sep 19, 2008 6:34 am 
Newbie

Joined: Mon May 26, 2008 6:09 am
Posts: 8
Hi,

I am new to hibernate and going over Hibernate One-toMany mapping.
I have created all necessary entries and which saving i am able to save records both in parent and child table. My child is a Set.

My main problem is that while retrieving Parent, it is not populated with child values. It is showing Child as null.

Can you please suggest that where i can be wrong?

Thanks,
Gaurav


Top
 Profile  
 
 Post subject: use lazy="false" or explicitly use the outer join
PostPosted: Fri Sep 19, 2008 7:39 am 
Newbie

Joined: Fri Sep 19, 2008 6:59 am
Posts: 6
Hi,

Currently, you will be having the lazy setting as false (which is the default).
You need to either give lazy="false" in the set mapping.

or a better way would be to use the fetch join on the set entity using HQL since this would improve the performance and you could only get the columns that you want but that does involve some amount of hard coding...

_________________
Rahul


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 19, 2008 9:54 am 
Newbie

Joined: Mon May 26, 2008 6:09 am
Posts: 8
Thanks a lot for your answer, but when i make lazy="false", then it started giving me below error at runtime:

could not initialize a collection


Top
 Profile  
 
 Post subject: please post your code sample
PostPosted: Fri Sep 19, 2008 11:46 pm 
Newbie

Joined: Fri Sep 19, 2008 6:59 am
Posts: 6
Hi,

Can you post the sample of the code?

In any case, you can try the Fetch Join using HQL.

Your query should be something like

Select a.a1, b.b1, b.b2 from a left join fetch b where <any where condition for a or b or both >

In the above query, a is supposed to have one to many mappings to b, i.e. there are many b in a.

Check the exact syntax and usage of this query.

Also, it will work even if the lazy is set to true.

_________________
Rahul


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.