-->
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.  [ 1 post ] 
Author Message
 Post subject: Parent / Childern Persistance Problem
PostPosted: Sun Mar 13, 2005 5:38 pm 
Newbie

Joined: Sun Mar 13, 2005 4:58 pm
Posts: 1
When I'm trying to save the following parent / child relationship, only the parent class is being persisted but not the children. If I call session.save(child) for each child it works. Is this right, or can save everything by just calling session.save(parent)?

Code:
test code:
SessionFactory sf = PersistanceManager.getSessionFactoy();      
Auftrag auftrag = new Auftrag();
AuftragPosition auftragposition = new AuftragPosition();
auftragposition.setAuftragnummer(auftrag);
auftrag.addAuftragposition(auftragposition);      
      
Session session = sf.openSession();
Transaction tx = session.beginTransaction();
session.save(auftrag);            
tx.commit();
session.close();



<hibernate-mapping package="dao">
<class name="dao.Auftrag">
  <id name="auftragnummer">
   <generator class="increment"/>
  </id>
  ........
  <list cascade="all" inverse="true" name="auftragpositionen">
   <key column="auftragnummer"/>
   <index column="position" type="int"/>
   <one-to-many class="dao.AuftragPosition"/>
  </list>
</class>
</hibernate-mapping>

<hibernate-mapping package="dao">
<class name="dao.AuftragPosition">
  <id name="auftragposid">
   <generator class="increment"/>
  </id>
........
  <many-to-one cascade="all" class="dao.Auftrag" column="Auftragnummer"
   name="auftragnummer" not-null="true"/>
</class>
</hibernate-mapping>


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.