Sleep mode. Matching the same column twice

How to fix it?

Duplicate column in the mapping for the object: com.abc.domain.PersonConnect column: PERSON_ID (must be mapped to insert = "false" update = "false")

this is a 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 is as follows

Person_Connect

  • PK - PARENT_PERSON_ID
  • PK - CHILD_PERSON_ID

Person

  • PK - PERSON_ID
  • Fname
  • Lname
+4
source share
2 answers

Your mapping is wrong, this is the correct mapping. On the many-to-one side, a column name is a column in the same table that is foreign, referring to 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> 
+2
source

Well, firstly, it is unlikely that both parents and the child are mapped to the same column. This is 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 one property. Otherwise, you may find yourself in unsolvable situations when one property says that the value must be x , and another says that it must be y .

+1
source

All Articles