-1

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?

Maciaz
  • 1,084
  • 1
  • 16
  • 31
  • maybe the accepted answer to this question is also the answer to your question https://stackoverflow.com/questions/2728160/hibernate-cascade-delete-on-a-bag (don't forget the inverse="true" as mentioned in the comments of the accepted answer) – JavaMan Aug 27 '19 at 10:52
  • Are you sure you got a `ON DELETE CASCADE` within the DB foreign key specification? – Robert Kock Aug 27 '19 at 10:52

2 Answers2

1

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.

Olivier Depriester
  • 1,615
  • 1
  • 7
  • 20
0

try this

   <bag name="limits">
       <key column="USER_ID" on-delete="cascade"/>
       <one-to-many class="com.mac.kom.modules.limits.models.LimitsModel" />
    </bag>
Vipin CP
  • 3,642
  • 3
  • 33
  • 55