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: parent-child in collections
PostPosted: Fri Apr 16, 2004 1:00 pm 
Newbie

Joined: Thu Apr 15, 2004 12:00 pm
Posts: 13
I have a mapping file parent.hbm.xml which contains set of childs.

Parent.hbm.xml
-------------------
<set name="childSet" inverse="true" lazy="true" cascade="save-update" outer-join="true">
<key column="parent_id"/>
<one-to-many class="Child"/>
</set>

Child.hbm.xml
----------------
<many-to-one name="parent" column="parent_id" not-null="true"/>

In code:
--------
Parent p = new Parent();
//set other parent properties
HashSet s = new HashSet();
Child c = new Child();
//set other child properties
c.setParent(p);
s.add(c);
p.setChildSet(c);

Session session = getSessionFactory().openSession();

Transaction t = session.beginTransaction();
session.save(p);
t.commit();
session.close();

The above code is only creating parent entry in the db not child entry? why? Do I need to set any attributes in the mapping file in order to accomodate this?

I appreciate your help.


Top
 Profile  
 
 Post subject: Re: parent-child in collections
PostPosted: Thu Apr 22, 2004 5:02 am 
Newbie

Joined: Thu Apr 22, 2004 4:07 am
Posts: 1
Location: France
I have exactly the same problem.
I don't understand why it does't work because it's not very complicated.
Have you found any solutions to solve this problem ?

thanks a lot


sudhir wrote:
I have a mapping file parent.hbm.xml which contains
set of childs.

Parent.hbm.xml
-------------------
<set name="childSet" inverse="true" lazy="true" cascade="save-update" outer-join="true">
<key column="parent_id"/>
<one-to-many class="Child"/>
</set>

Child.hbm.xml
----------------
<many-to-one name="parent" column="parent_id" not-null="true"/>

In code:
--------
Parent p = new Parent();
//set other parent properties
HashSet s = new HashSet();
Child c = new Child();
//set other child properties
c.setParent(p);
s.add(c);
p.setChildSet(c);

Session session = getSessionFactory().openSession();

Transaction t = session.beginTransaction();
session.save(p);
t.commit();
session.close();

The above code is only creating parent entry in the db not child entry? why? Do I need to set any attributes in the mapping file in order to accomodate this?

I appreciate your help.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 22, 2004 5:25 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
1. Please read the equals()/hasCode() wiki page, It may be related.
2. check the SQL geenrated

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 22, 2004 9:35 am 
Senior
Senior

Joined: Wed Mar 24, 2004 11:40 am
Posts: 146
Location: Indianapolis, IN, USA
I had the same problem and found a solution. Discussed in two different threads if you are interested.

http://forum.hibernate.org/viewtopic.php?t=929969&highlight=
http://forum.hibernate.org/viewtopic.php?t=930119&highlight=


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.