-->
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: Persistence by Reachability?
PostPosted: Sun Jan 08, 2006 2:36 pm 
Newbie

Joined: Sun Jan 08, 2006 2:26 pm
Posts: 15
Hi its me again :-)

I am a bit confused... I dont get my Many-to-One Mappings work probably.

The case is: Class Order is containing an association to OrderDetails.

now if i try to save the Order with an unsafed OrderDetail i get an exception.

e.g.:

Order ord = new Order...

OrderDetails detail = new OrderDetails...

ord.Details = detail;

session.Save(ord);

...

If i save OrderDetails before, ist working fine. So might there be something wrong in my mapping or is it intend to work like this?

Thx again,

Chris


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jan 08, 2006 5:45 pm 
Newbie

Joined: Sun Jan 08, 2006 2:26 pm
Posts: 15
Sry forgot to write down the code...
Here it comes:

public class Kunde
{
private string name;
private string vorname;
private int kundenNr;
private Adresse adresse;
...
}

Kunde.hbm.xml:

<class name="NHTest.Kunde, NHTest" table="Kunde">
<id name="KundenNr" column="KundenNr" type="Int32">
<generator class="assigned" />
</id>
<property name="Name" column= "Name" type="String" length="40"/>
<property name="Vorname" type="String" length="20"/>
<many-to-one
name="Adresse"
column="Id"
cascade="all"
not-null="false"/>
</class>



public class Adresse
{
private int id;
private string strasse;
private int plz;
private string stadt;
...
}

Adresse.hbm.xml

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
<class name="NHTest.Adresse, NHTest" table="Adresse">
<id name="Id" column="Id" type="Int32">
<generator class="assigned" />
</id>
<property name="Strasse" column= "Strasse" type="String" length="40"/>
<property name="PLZ" column="PLZ" type="Int32"/>
<property name="Stadt" type="String" length="10"/>
</class>

</hibernate-mapping>

what am i doing wrong?

Thx anyway

Chris


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jan 08, 2006 8:23 pm 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
Eh... first you speak of order and order details, and then you show customers and addresses instead :)

Your problem is that you use assigned identifiers. Cascades (aka persistence by reachability) won't work correctly with them.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 09, 2006 5:30 am 
Newbie

Joined: Sun Jan 08, 2006 2:26 pm
Posts: 15
Hi thx for this hint!

Yeah i realized to late my mistake :-) I was to tired.

I wil check this out!

Chris


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.