Pradeep Kumar
Pradeep Kumar

Reputation: 79

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" 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

Person

Upvotes: 4

Views: 6809

Answers (2)

gkamal
gkamal

Reputation: 21000

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>

Upvotes: 2

Ryan Stewart
Ryan Stewart

Reputation: 128829

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.

Upvotes: 1

Related Questions