0

I have 3 classes A, B and C. And there relationships are:

  1. One to many bi-directional from A to B.
  2. C extends B.

I am able to add new records and edit existing records of address collection, but i am not able to remove any existing record.

Code to update Object

currentObj = getSession().merge(currentObj);

Mappings:

  1. Address.hbm.xml

    <joined-subclass name="test.domain.ParticipantAddress"
            table="PARTICIPANT_ADDRESS"
            dynamic-update="false"
            dynamic-insert="false"
            lazy="true"
        >
        <key
            column="IDENTIFIER"
        />
        <many-to-one name="participant" class="test.domain.Participant"
            column="PARTICIPANT_ID" not-null="false" cascade="none" unique="true"/>
    
         <property
            name="sortOrder"
            type="long"
            update="true"
            insert="true"
            column="sortOrder"
            length="255"
        />
        </joined-subclass>
    
  2. Participant.hbm.xml

        <list name="addressCollection" table="PARTICIPANT_ADDRESS"
        lazy="false"
        inverse="true"
        cascade="all">
            <cache usage="read-write"/>
            <key column="PARTICIPANT_ID"/>
            <list-index column="sortOrder"/>
            <one-to-many class="test.domain.ParticipantAddress"/>
    </list>
    

I also tried using cascade="all,delete-orphan" but it's also throwing error "A collection with cascade=”all-delete-orphan” was no longer referenced by the owning entity instance"

Atul
  • 1,536
  • 3
  • 21
  • 37

1 Answers1

0

Check what foreign key constraint you have in table B, if it doesn't allow deletion of A prior to B then you'll see this behavior. Remember that whatever you do on hibernate will be translated into SQL DML/DDL

gerrytan
  • 40,313
  • 9
  • 84
  • 99