简体   繁体   中英

Cascade=delete doesn't delete related entities

I do have 2 entities:
1. User
2. Limits

User has a set of limits, so one-to-many relation is present. I do have a cascade type set to delete , so when User is deleted, all corresponding limits should be deleted as well.

<bag name="limits" cascade="delete">
   <key column="USER_ID"/>
   <one-to-many class="com.mac.kom.modules.limits.models.LimitsModel" />
</bag>

When I try to delete the User I do get an error

Caused by: java.sql.SQLException: ORA-01407: cannot update ("DB"."LIMITS"."USER_ID") to NULL

Any clues?

You should cascade delete-orphan .
delete tries to break the link between the both entities by clearing the FK field.
delete-orphan won't authorize having some LimitsModel without User and thus will delete the related LimitsModel record.

try this

   <bag name="limits">
       <key column="USER_ID" on-delete="cascade"/>
       <one-to-many class="com.mac.kom.modules.limits.models.LimitsModel" />
    </bag>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM