Hibernate Mapping same Column twice
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" 开发者_如何学Goname="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
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.
<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>
</class>
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 be x
and the other says it should be y
.
精彩评论