-->
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: A problem about one-to-one
PostPosted: Wed Aug 31, 2005 3:45 am 
Newbie

Joined: Tue Aug 30, 2005 10:51 pm
Posts: 2
I have two tables in the Database which are production and image.every record in then production have only one record in image.So i want to store the data into 2 java files named the Product and Image.In the product.java ,i defined "private Image photo;"so it is a one-to-one relation.

When i want to using it ,i have written the
session.saveOrUpdate(product);
But there is only an update sentence in the console,which is update the table of product.when i changed it to the
session.save(product);
there have 2 sentence ,insert product and update image.

Both 2 cases is wrong then the transation is committing, the exception is "org.hibernate.HibernateException: Unexpected row count: 0 expected: 1".

why is it ?

Here is the hbm.xml file:

<class name="Image" dynamic-insert="true" dynamic-update="true" lazy="false">
<id name="id" column="iId">
<generator class="increment"/>
</id>
<property name="name" column="iName"/>
<property name="value" column="iValue"/>
</class>

<class name="Product" table="product" dynamic-insert="true" dynamic-update="true" lazy="false">
<id name="id" column="pId">
<generator class="increment"/>
</id>
<property name="name" column="pName"/>
<property name="description" column="pDescription"/>
<property name="price" column="pPrice"/>
<one-to-one name="photo" class="Image" cascade="all" constrained="true" foreign-key="PIMAGEID"/>
</class>


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 31, 2005 3:55 am 
Newbie

Joined: Tue Aug 30, 2005 10:51 pm
Posts: 2
And when i was practising many-to-one example, i also happened.so i was very confounded.

Please help me !


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.