一对一映射说明

时间:2019-07-05 17:18:37

标签: hibernate

我有两个桌子

  1. 员工表
  2. 地址表

Employee Table hbm定义将具有以下内容

<id name="empGkey" column="primarykey" type="java.lang.Long" unsaved-value="null">
       <generator class="native"/>
   </id>
<many-to-one name="empAddress" column="address" class="com.region.Address"
cascade="all" unique="false"> </many-to-one>

地址表hbm定义将具有以下内容

<id name="addressGkey" column="primarykey" type="java.lang.Long" unsaved-value="null">
       <generator class="native"/>
   </id>
   <one-to-one name="addressEmp" class="com.region.Employee" property-ref="empAddress">
   </one-to-one>

当前,当执行以下HQL查询时,应用程序将引发以下异常

from Address where primarykey = '1232';

More than one row with the given identifier was found: 1232, for class: 
com.region.Employee (compact stack trace follows) 
org.hibernate.loader.entity.AbstractEntityLoader.load
(AbstractEntityLoader.java:92)

澄清

1. Will Address primary key will always have one similar primary key in 
   Employee?
2. Will the Address primary key might differs from Employee primary key 
   column
3. Will the Address primary key will always have one similar address column
   value in Employee table?
4. When this issue might come?
5. How to fix the problem

谢谢。

1 个答案:

答案 0 :(得分:0)

您的休眠配置中似乎有问题。 员工指的是一对多的地址:

与“地址”一词一样,您将Employee称为一对一

请您确认您的确切要求是什么?

相关问题