-->
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: Problem with parent/child relationship
PostPosted: Tue Jan 06, 2004 6:06 am 
Newbie

Joined: Tue Jan 06, 2004 5:52 am
Posts: 17
Location: Belgium
Hi,

I have this class:

Code:
public class Vak
{
    private String _id;
    private String _name;
    private List _subVakken;
    private Vak _parentVak;
}

with corresponding get and set methods for all fields. The List _subVakken contains again "Vak"-objects where this Vak is then in the field _parentVak.

I have this hibernate mapping:

Code:
<hibernate-mapping>
<class name="com.misoftware.reports.models.Vak" table="VAK">
  <id name="id" type="string" unsaved-value="null">
  <column name="id" not-null="true"/>
  <generator class="uuid.hex"/>
</id>

<property name="name" type="string"/>
<bag name="subVakken" inverse="true" lazy="true">
  <key column="parentVak_id"/>
  <one-to-many class="com.misoftware.reports.models.Vak"/>
</bag>
<many-to-one name="parentVak" class="com.misoftware.reports.models.Vak" column="parentVak_id"/>
</class>
</hibernate-mapping>


This does not seem to work. The List _subVakken is empty if I read the object back from hibernate if I close and re-open the session before reading.

Can someone tell me what is wrong with my mapping?

When I save the object I only call session.saveOrUpdate on the parent "Vak" (the field _parentVak is null in that case)

regards,

Wim


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 06, 2004 12:10 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
http://www.hibernate.org/hib_docs/reference/html_single/#parent-child
Read it carefully

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 06, 2004 12:21 pm 
Newbie

Joined: Tue Jan 06, 2004 5:52 am
Posts: 17
Location: Belgium
Looks like the cascade attribute is what I was missing. Thank you for your help, I'll try it out!


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.