-->
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.  [ 2 posts ] 
Author Message
 Post subject: Please Help, simple One-To-One Assocation
PostPosted: Wed Jan 17, 2007 8:13 am 
Newbie

Joined: Fri Dec 01, 2006 11:36 am
Posts: 6
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"/>
...






Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 17, 2007 9:59 am 
Senior
Senior

Joined: Sat Mar 25, 2006 9:16 am
Posts: 150
You should change your unsaved-value to something that makes sense for an int, (i.e., "0")


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.