Hibernate one-to-many relationship together with Oracle integrity referential

Description

We defined a one to many relationship between two tables: Role and RoleAccount.
We managed the integrity referential directly on Oracle.
Our need is to delete one or more RoleAccount related to a Role, but we also need to keep an Oracle integrity referential when we try to delete a Role that has at least a RoleAccount linked.

So what we expect from Hibernate is that there would exist a cascade option, besides delete and delete-orphan, that when trying to delete a Role that has at least a RoleAccount, it doesn't delete first the orphans and then the parents, but the opposite so to raise an integrity referential exception.

Instead if we use delete-orphan option, Hibernate first deletes all the orphan children(RoleAccounts) and then delete the parent(Role), without raising any Oracle integrity referential exception.
We know that this can be done by removing the delete option from cascade (cascade="save-update"), but then we manually have to delete RoleAccounts.

Below I attached part of the mappings and integrity referential sql script:
<!----------------Role -------------->
<bag name="roleFunctions" table="`AdmRoleFunction`" inverse="true" fetch="select" cascade="save-update">
<key>
<column name="`admRoleId`" not-null="true" />
</key>
<one-to-many class="it.apra.logistic.model.admin.RoleFunction" />
</bag>
<!----------------RoleAccounts -------------->
<bag name="roleAccounts" table="`AdmRoleAccount`" inverse="false" fetch="select" cascade="save-update,delete">
<key>
<column name="`admRoleId`" not-null="true" />
</key>
<one-to-many class="it.apra.logistic.model.admin.RoleAccount" />
</bag>

<!------Integrity referential Sql-------------->
ALTER TABLE "AdmRoleAccount" ADD CONSTRAINT "FkAdmRole2" FOREIGN KEY ("admRoleId") REFERENCES "AdmRole" ("id") /
ALTER TABLE "AdmRoleAccount" ADD CONSTRAINT "FkAdmAccount2" FOREIGN KEY ("admAccountId") REFERENCES "AdmAccount" ("id") ON DELETE CASCADE /

Attachments

1
  • 15 Jun 2011, 05:46 PM

Activity

Brett MeyerMarch 7, 2014 at 5:30 PM

Bulk closing rejected tickets in "resolved" state.

Former userAugust 16, 2011 at 12:11 AM

Delete-orphan is designed to work as you describe.

Please use the user forum for help (https://forum.hibernate.org/).

Rejected

Details

Assignee

Reporter

Components

Affects versions

Priority

Created June 15, 2011 at 5:46 PM
Updated March 7, 2014 at 5:30 PM
Resolved August 16, 2011 at 12:11 AM

Flag notifications