-->
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.  [ 3 posts ] 
Author Message
 Post subject: one-to-one: foreign key: save Problem
PostPosted: Mon Jul 06, 2009 6:48 am 
Beginner
Beginner

Joined: Wed Aug 22, 2007 5:53 am
Posts: 38
I have one-to-one relationship between class A and class B

<class name="A" table="TEMPA" >
<id name="aaId" type="string" column="AID" length="10">
<generator class="assigned"></generator>
</id>

<one-to-one name="b" class="B" constrained="true" outer-join="false" cascade="save-update" />
</class>


<class name="B" table="TEMPB" lazy="true">
<id name="baId" type="string" column="BID" length="10">
<generator class="foreign">
<param name="property">a</param>
</generator>
</id>

<one-to-one name="a" class="A" />
</class>

Problem 1: When i try to save A, it fires :
insert into HBLEARN1.TEMPB (BID) values ('1')
and throws error :
The insert or update value of the FOREIGN KEY "TEMPB.CC1246876555824" is not equal to any value of the
parent key of the parent table. SQLSTATE=23503

Why it is first trying to save 'B' instead of 'A' first ?

Problem 2: With this mapping, if i set <property name="hibernate.hbm2ddl.auto">create</property> in hibernate.cfg.xml,
It generates TEMPA whose aaId is the foreign key referencing TEMPB. This is also incorrect..


Top
 Profile  
 
 Post subject: Re: one-to-one: foreign key: save Problem
PostPosted: Mon Jul 06, 2009 7:09 am 
Beginner
Beginner

Joined: Wed Jun 17, 2009 9:03 pm
Posts: 31
Location: mumbai
Hi try with constrained on entity B side mapping.


<class name="A" table="TEMPA" >
<id name="aaId" type="string" column="AID" length="10">
<generator class="assigned"></generator>
</id>

<one-to-one name="b" class="B" outer-join="false" cascade="save-update" />
</class>


<class name="B" table="TEMPB" lazy="true">
<id name="baId" type="string" column="BID" length="10">
<generator class="foreign">
<param name="property">a</param>
</generator>
</id>

<one-to-one name="a" class="A" constrained="true"/>
</class>


Top
 Profile  
 
 Post subject: Re: one-to-one: foreign key: save Problem
PostPosted: Mon Jul 06, 2009 7:51 am 
Beginner
Beginner

Joined: Wed Aug 22, 2007 5:53 am
Posts: 38
Thanks It Worked !!!


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