I implemented everything like it is shown in Hibernate in Action, 6.3.1, One-to-One: using foreign-key assocation
Loading works perfect, but when i want to save, i get a NonUniqueObjectException: {"a different object with the same identifier value was already associated with the session: 7467, of class: PM.BO.Info"}
Can anybody tell me, what i did wrong?
Class Info:
Code:
public class Info {
private int id;
private Notiz notiz;
public Info(){}
public Notizen Notizen
{
get { return notiz;}
set { notiz = value;}
}
public int ID
{
get { return id}
set { id= value; }
}
}
Class Notizen:
Code:
public class Notizen {
private int id;
private Info info;
public Notizen(){}
public int ID
{
get { return id; }
set {id=value;}
}
public Info Info
{
get { return info;}
set {info = value;}
}
}
Mapping Info:
Code:
<class name="Info" table="Info" lazy="false">
<id name="ID" column="ID" type="Int32" unsaved-value="null">
<generator class="native"/>
</id>
<one-to-one name="Notizen" class="Notizen" cascade="save-update" property-ref="Info"/>
...
Mapping Notizen:
Code:
<class name="Notizen" table="Notizen">
<id name="ID" column="ID" type="Int32" unsaved-value="null">
<generator class="identity"/>
</id>
<many-to-one name="Info"
column="info_fk"
class="Info"
cascade="save-update"
unique="true"/>
...