-->
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: Question about one-to-one relation
PostPosted: Mon Jan 12, 2004 7:30 am 
Newbie

Joined: Mon Jan 12, 2004 7:05 am
Posts: 16
I have defined a one-to-one Relationship for model.CatPersistent to the model.PersonPersistent.

<class name="test.Cat" table="CAT">

<id name="id" type="long" unsaved-value="null" >
<column name="ID" not-null="true"/>
<generator class="native"/>
</id>

<property name="name">
<column name="NAME" sql-type="varchar(16)" not-null="true"/>
</property>

<property name="sex"/>

<property name="weight"/>

<one-to-one name="owner" class="test.Person" constrained="true" cascade="all" property-ref="id"/>


</class>

<class name="test.Person" table="person">

<id name="id" type="long" unsaved-value="null" >
<column name="ID" not-null="true"/>
<generator class="native"/>
</id>

<property name="name"/>

</class>


and execute the following code.

Transaction tx1 = session.beginTransaction();

Person owner = new Person();
owner.setName("listopad");
session.save(owner);

Cat princess = new Cat();
princess.setName("Princess");
princess.setOwner(owner);
session.save(princess);

tx1.commit();

two datasets will be inserted in the database, but the owner column from the table cat has value null instead of the id of the inserted person.
the id columns of table person and cat are definded as auto_increment.

Can someone help me to find the failure?

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 12, 2004 9:05 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
If I guess well, you don't want to have the same id between the 2 sides of the one-to-one.
Then remove constrained="true" and recheck the 5.1.11 sample[/code]

_________________
Emmanuel


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.