Anton
Anton

Reputation: 575

Hibernate does not insert field which is part of composite FK

I have hibernate entity with two many-to-one associations and composite foreign keys, each with 3 fields. Two fields are common for both keys. There are mapping:

<class dynamic-insert='true' dynamic-update='true' entity-name='...' table='...'>
    <composite-id>
        <key-property name='FaultId' type='long' column='FAULT_ID'/>
        <key-property name='RowVersion' type='long' column='ROWVERSION'/>
    </composite-id>
    <many-to-one name='Pot' class='Pot'>
        <column name='SMELTER_ID' not-null='true'/>
        <column name='ROOM_ID' not-null='true'/>
        <column name='POT_ID' not-null='true'/>
    </many-to-one>
    <many-to-one name='Event' class='PotEventRef_NonGui'>
        <column name='EVENT_ID' not-null='true'/>
    </many-to-one>
    <many-to-one name='Shift' class='TimeShift' insert='false' update='false'>
        <column name='SMELTER_ID' not-null='true'/>
        <column name='ROOM_ID' not-null='true'/>
        <column name='TIMESHIFT' not-null='true'/>
    </many-to-one>
</class>

Code for inserting entity:

session.persist(entry.getName(), entry.getData());

where session - org.hibernate.Session, entry.getName() - String, entry.getData() - Map<String, Object>.

When i try to insert entity of this class, TIMESHIFT field is not inserted. (Shift object is set and all values are correct). What can be source of problem?

Upvotes: 0

Views: 306

Answers (1)

Rohit Gaikwad
Rohit Gaikwad

Reputation: 3914

try by changing update value to true & by removing insert='false' in the XML.

<many-to-one name='Shift' class='TimeShift' update='true'>

Upvotes: 0

Related Questions