This week's book giveaway is in the
We're giving away four copies of
Head First Android
and have Dawn & David Griffiths on-line!
A friendly place for programming greenhorns!
Big Moose Saloon
Register / Login
Win a copy of
Head First Android
this week in the
Object Relational Mapping
Hibernate one-to-many relationship insert
Joined: Aug 19, 2003
Jul 16, 2007 06:03:00
I am having a 1-to-many relationship btw Parent and child class....In the parent class i am something like
private Set children = new HashSet(); public void setChildren(Set children)... public Set getChildren() The parent hbm mapping file has: <set name="children"> <key column="child_ID"/> <one-to-many class="com.test.Child"/> </set>
While inserting records in the db, my code is:
Parent p = new Parent(); Set child1 = new HashSet(); ....populate child 1 data Set child 2 = new HashSet(); ....populate child 2 data p.getChildren().add(child1); p.getChildren().add(child2); session.save(p);
The above code inserts successfully in the parent db but does not insert in the child table
Any ideas?....I have tried "inverse=true" as well...Do i need to define a Many-to-one in child as well?
[ July 16, 2007: Message edited by: Nischal Tanna ]
Joined: Feb 05, 2001
Jul 16, 2007 09:38:00
What are your cascade options set to for this relationship? you will probably want it set to "save-update".
Perfect World Programming, LLC
Two Laptop Bag
How to Ask Questions the Smart Way FAQ
I agree. Here's the link:
subject: Hibernate one-to-many relationship insert
what changes should i made in save method in one-to-many relationships
retrieving object hierarchy - many-to-one?
Please help: What is the best strategy to update the DB using a detached object?
cascade vs inverse
Error when saving relationship
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter
| Powered by
Copyright © 1998-2015