Hibernate 映射同一列两次
如何解决这个问题
实体映射中的重复列:com.abc.domain.PersonConnect 列:PERSON_ID(应使用 insert="false" 进行映射 更新=“假”)
这是我的 hbm 文件中的片段
<class name="com.abc.domain.PersonConnect" table="PERSON_CONNECT">
<composite-id>
<key-many-to-one name="Parent" class="com.abc.domain.Person" column="PARENT_PERSON_ID"/>
<key-many-to-one name="Child" class="com.abc.domain.Person" column="CHILD_PERSON_ID"/>
</composite-id>
<many-to-one class="com.abc.domain.Person" fetch="select" name="parent" lazy="false" >
<column length="20" name="PERSON_ID" not-null="true"/>
</many-to-one>
<many-to-one class="com.abc.domain.Person" fetch="select" name="child" lazy="false" >
<column length="20" name="PERSON_ID" not-null="true"/>
</many-to-one>
</class>
,表格如下所示
Person_Connect
- PK - PARENT_PERSON_ID
- PK - CHILD_PERSON_ID
Person
- PK - PERSON_ID
- FNAME
- LNAME
How can fix this thing
Repeated column in mapping for entity: com.abc.domain.PersonConnect
column: PERSON_ID (should be mapped with insert="false"
update="false")
this is snippet from my hbm file
<class name="com.abc.domain.PersonConnect" table="PERSON_CONNECT">
<composite-id>
<key-many-to-one name="Parent" class="com.abc.domain.Person" column="PARENT_PERSON_ID"/>
<key-many-to-one name="Child" class="com.abc.domain.Person" column="CHILD_PERSON_ID"/>
</composite-id>
<many-to-one class="com.abc.domain.Person" fetch="select" name="parent" lazy="false" >
<column length="20" name="PERSON_ID" not-null="true"/>
</many-to-one>
<many-to-one class="com.abc.domain.Person" fetch="select" name="child" lazy="false" >
<column length="20" name="PERSON_ID" not-null="true"/>
</many-to-one>
</class>
and the table goes like this
Person_Connect
- PK - PARENT_PERSON_ID
- PK - CHILD_PERSON_ID
Person
- PK - PERSON_ID
- FNAME
- LNAME
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你的映射是错误的,这是正确的映射。在多对一方面,列名是同一个表中的列,它是引用 Person 的主键的外部列。
Your mapping is wrong, this is the correct mapping. On the many-to-one side the column name is the column in the same table which is a foreign referring the primary key of Person.
嗯,一方面,“父级”和“子级”似乎不太可能映射到同一列。这可能是个问题。否则,请按照错误提示执行操作,并将
insert="false" update="false"
添加到列映射之一。一列只能“属于”单个属性。否则,您可能会遇到无法解决的情况,其中一个属性说该值应该是x
而另一个属性说它应该是y
。Well, for one, it seems unlikely that both "Parent" and "Child" should be mapped to the same column. That's probably a problem. Otherwise, do what the error says, and add
insert="false" update="false"
to one of the column mappings. A column can only "belong" to a single property. Otherwise you can get into unresolvable situations where one property says the value should bex
and the other says it should bey
.