hibernate联合主键做外键时两个many-to-one中有相同属性怎么办?
下面的例子不是真实案例(请勿纠结),但意思相同。<many-to-onename="student"class="org.apache.dream.common.enti...
下面的例子不是真实案例(请勿纠结),但意思相同。
<many-to-one name="student" class="org.apache.dream.common.entity.Student">
<column name="STUDENT_ID" />
<column name="CLASS_NO" />
</many-to-one>
<many-to-one name="teacher" class="org.apache.dream.common.entity.Teacher">
<column name="TEACHER_ID" />
<column name="CLASS_NO" />
</many-to-one>
这时会报错:
org.hibernate.MappingException: Repeated column in mapping for entity: org.apache.dream.common.entity.XXXXXX.XXXXXX column: CLASS_NO (should be mapped with insert="false" update="false")
<class name="XXXXX" table="t_XX">
<id name="id">
<generator class="native"></generator>
</id>
<many-to-one name="student" class="org.apache.dream.common.entity.Student">
<column name="STUDENT_ID" />
<column name="CLASS_NO" />
</many-to-one>
<many-to-one name="teacher" class="org.apache.dream.common.entity.Teacher">
<column name="TEACHER_ID" />
<column name="CLASS_NO" />
</many-to-one>
</class> 展开
<many-to-one name="student" class="org.apache.dream.common.entity.Student">
<column name="STUDENT_ID" />
<column name="CLASS_NO" />
</many-to-one>
<many-to-one name="teacher" class="org.apache.dream.common.entity.Teacher">
<column name="TEACHER_ID" />
<column name="CLASS_NO" />
</many-to-one>
这时会报错:
org.hibernate.MappingException: Repeated column in mapping for entity: org.apache.dream.common.entity.XXXXXX.XXXXXX column: CLASS_NO (should be mapped with insert="false" update="false")
<class name="XXXXX" table="t_XX">
<id name="id">
<generator class="native"></generator>
</id>
<many-to-one name="student" class="org.apache.dream.common.entity.Student">
<column name="STUDENT_ID" />
<column name="CLASS_NO" />
</many-to-one>
<many-to-one name="teacher" class="org.apache.dream.common.entity.Teacher">
<column name="TEACHER_ID" />
<column name="CLASS_NO" />
</many-to-one>
</class> 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询