-->
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.  [ 3 posts ] 
Author Message
 Post subject: How save child without loading parent?
PostPosted: Fri Oct 29, 2004 4:09 pm 
Newbie

Joined: Fri Aug 13, 2004 12:17 pm
Posts: 12
Location: St. Louis, MO
Hibernate version: 2.1.6

Mapping documents: n/a

Code between sessionFactory.openSession() and session.close(): n/a

Full stack trace of any exception that occurs: n/a

Name and version of the database you are using: Postgresql 8

The generated SQL (show_sql=true): n/a

Debug level Hibernate log excerpt: n/a

I have a case where I am returned the ID of a parent in a Many-To-One relationship and I would like to add a child to the parent without first loading the parent in order to avoid the additional database query. In jdbc this would be accomplished via setting the foriegn key in the child record to equal the parent id. How is this accomplished in hibernate?

Thanks in advance.

Ryan


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 01, 2004 8:31 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Code:
Parent p = new Parent();
p.setId(parentId);
child.setParent(p);
session.saveOrUpdate(child);

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 01, 2004 10:32 am 
Newbie

Joined: Fri Aug 13, 2004 12:17 pm
Posts: 12
Location: St. Louis, MO
This requires an inverse relationship and cascade="none" set on the child to parent relationship, correct?


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