-->
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: circular reference / mapping pb?
PostPosted: Tue Feb 15, 2005 2:26 pm 
Newbie

Joined: Thu Jan 27, 2005 5:32 am
Posts: 3
Location: Paris
Read the rules before posting!
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version: 2.1.17

Mapping documents:

Name and version of the database you are using: Firebird

The generated SQL (show_sql=true):

Hi all!

first i want to thank the Hibernate community for their contributions / information especially on the Wiki. I found a lot of help here. :)

Here is my problem : i want to do a circular reference.

My class :

Code:
public class BasePatient implements Serializable {

    /** identifier field */
    private Long key;

    /** persistent field */
    private String lastName;

    /** persistent field */
    private String firstName;

    /** persistent field */
    private Date birthday;

    /** nullable persistent field */
    private Patient ensuredBy;

    public void setEnsuredBy(Patient ensuredBy) {
        this.ensuredBy = ensuredBy;
    }




and the mapping file : patient.hbm.xml

Code:
<hibernate-mapping package="patient">
   <class name="Patient" table="PAT">
      <id name="key" column="PAT_KEY" type="long">
         <generator class="sequence">
            <param name="sequence">PAT_GEN</param>
         </generator>
      </id>
      <property name="lastName" column="PAT_NOM" type="string" not-null="true" length="50">
      </property>
      <property name="firstName" column="PAT_PRE" type="string" not-null="true" length="50">
      </property>
      <property name="birthday" column="PAT_NAI" type="date" not-null="true">
      </property>
      <many-to-one class="patient.Patient" cascade="none"
         name="ensuredBy" column="PAT_ASS" not-null="false" insert="false" update="false">
      </many-to-one>
   </class>
</hibernate-mapping>


when i do :

Code:
Patient a;
Patient b;
...
b.setEnsuredBy(a);
session.saveOrUpdate(a);
session.saveOrUpdate(b);


i get update for the fields that changed. But the reference between the two entities is never recorded. (ie the colomn PAT_ASS is always null whereas i'm waiting for b.PAT_ASS=a.PAT_KEY).

Can someone help me? how can i do this kind of reference?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 15, 2005 2:29 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
Why is that insert=false update=false there?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 16, 2005 5:18 am 
Newbie

Joined: Thu Jan 27, 2005 5:32 am
Posts: 3
Location: Paris
Well i didn't want to propagate the changes.
i think you should be right if i remove this.
i'll try. Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 16, 2005 6:50 am 
Newbie

Joined: Thu Jan 27, 2005 5:32 am
Posts: 3
Location: Paris
Ok i remember now ^^'

the mapping file used to be :
Code:
<many-to-one class="com.agdf.apsi.patient.Patient" cascade="none"
         name="ensuredBy" column="PAT_KEY" not-null="false" >
      </many-to-one>

the log with this config was : (while launching)
Code:
net.sf.hibernate.MappingException: Repeated column in mapping for class com.agdf.apsi.patient.Patient should be mapped with insert="false" update="false": PAT_KEY

here is the explanation ^^'

Thanks for help :)


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.