-->
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: Problems with saving bidirectional associations
PostPosted: Sat Sep 06, 2003 9:12 am 
Newbie

Joined: Sat Sep 06, 2003 9:02 am
Posts: 2
Location: Germany
Hi,

there is some trouble with saving a bidirectional association. I am setting the objects at both ends like it is described in the FAQ, but I always getting a SQL error update or deletion failed (row not found).
Here is my hbm.xml file

<hibernate-mapping>

<class name="de.laboranowitsch.efm.ta.test.dao.Bestellung" table="BESTELLUNG">
<id name="id" type="long">
<generator class="sequence">
<param>BESTELLUNG_ID_SEQ</param>
</generator>
</id>
<property name="Kunde" type="string"/>
<property name="BestellDatum" type="date"/>
<property name="LieferDatum" type="date"/>
<set role="bestellPos" lazy="true">
<key column="BestellId"/>
<one-to-many class="de.laboranowitsch.efm.ta.test.dao.BestellPosition"/>
</set>
</class>

<class name="de.laboranowitsch.efm.ta.test.dao.BestellPosition" table="BESTELLPOS">
<id name="id" type="long">
<generator class="sequence">
<param>BESTELLPOS_ID_SEQ</param>
</generator>
</id>
<property name="Artikel" type="string"/>
<property name="Anzahl" type="integer"/>
<many-to-one name="bestellung" column="BestellId" class="de.laboranowitsch.efm.ta.test.dao.Bestellung" cascade="save-update"/>
</class>

</hibernate-mapping>

The java code looks like:

public void testCommit(){
try{

HashSet set = new HashSet();

BestellPosition bp = new BestellPosition();
bp.setArtikel("Schere");
bp.setAnzahl(2);

Bestellung bs = new Bestellung();

bs.setKunde("John Speyer");
bs.setBestellDatum(new Date());
bs.setLieferDatum(new Date());
bp.setBestellung(bs);
set.add(bp);
bs.setBestellPos(set);
Long pk = testDao.insertBestellung(bs);
testDao.commit();
assertEquals("John Speyer",testDao.findBestellungByKey(pk.longValue()).getKunde());
}catch(Exception exc){
exc.printStackTrace(System.out);
fail(exc.getMessage());
}
}
}

Any ideas?
Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Sat Sep 06, 2003 9:18 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
unsaved-value="0" is required on both id mappings!


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 08, 2003 3:24 pm 
Newbie

Joined: Sat Sep 06, 2003 9:02 am
Posts: 2
Location: Germany
Hi,

thanks for your help, but the error is still there. I have added the unsaved-value = "0" attribute to the hbm.xml file. I am using Postgresql 7.2.1. To me it looks more like a problem with the cascade-update. Does anyone has some additional ideas.

Chris


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 08, 2003 6:18 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Well, read the Parent/Child relationship doco twice.

Setting unsaved-value="0" is the most common example of a class of fixes which are described there.

The problem is: "how does Hibernate distinguish b/w newly instantiated instances and instances persistent in a previous session"


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.