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>
|