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
|