-->
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.  [ 5 posts ] 
Author Message
 Post subject: Adding to lazy collection
PostPosted: Thu Sep 16, 2004 1:09 pm 
Beginner
Beginner

Joined: Wed Feb 25, 2004 10:58 am
Posts: 43
Hibernate version: 2.1.6

Mapping documents:

Code between sessionFactory.openSession() and session.close():

Full stack trace of any exception that occurs:

Name and version of the database you are using:

The generated SQL (show_sql=true):

Debug level Hibernate log excerpt:

When adding to a collection does the collection always have to be intialized (cannot be collection proxy) ? If so is it bad practice to add to the many side be setting the detail object (many side) object to point to to the parent object and just save the detail object. Almost all examples I have seen are cases where child records are always added through the parent but I don't really want to intialize the collection to add details to it since it is so big.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 16, 2004 3:38 pm 
Proxool Developer
Proxool Developer

Joined: Tue Aug 26, 2003 10:42 am
Posts: 373
Location: Belgium
Wondering if the "reverse" keyword on your collection mapping is not what you need.

Check the doc at various places. Look for the collection mapping info and the


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 16, 2004 4:01 pm 
Beginner
Beginner

Joined: Wed Feb 25, 2004 10:58 am
Posts: 43
yes this is correct , however , when u access the the collection to add the child the collection still needs to be intialized.

Parent.addChild(new Child());

with inverse="true" .. the child will do the insert but hibernate will still initialize the collection of the parent. What I am doing now is just saving the child by and pointing it to the parent.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 16, 2004 4:06 pm 
Proxool Developer
Proxool Developer

Joined: Tue Aug 26, 2003 10:42 am
Posts: 373
Location: Belgium
sboulay wrote:
yes this is correct , however , when u access the the collection to add the child the collection still needs to be intialized.

Parent.addChild(new Child());

with inverse="true" .. the child will do the insert but hibernate will still initialize the collection of the parent. What I am doing now is just saving the child by and pointing it to the parent.


What you do is correct (according to me).

* insert the child and point it to the parent (using a many-to-one);

* in the parent, you can still have a collection of the children (as an unindexed collection - set or bag) mapped with the *inverse* keyword. This keyword actually says the relationship between parent and child is actually managed by the child...

Using this strategy, you don't access the parent's children collection - so Hibernate shouldn't initialize it.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 16, 2004 4:19 pm 
Beginner
Beginner

Joined: Wed Feb 25, 2004 10:58 am
Posts: 43
perfect , this helps .. just wanted to make sure I am on the right track. For me .. the performance implication of say loading 50,000 child objects to insert one extra child was not a good a thing.

Thanks for your help and quick reply


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