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 /

Environment

JBoss 6.0 standard community edition. Eclipese Helios. Hibernate 3.6.0.

Activity

Show:
Gail Badner
August 16, 2011, 12:11 AM

Delete-orphan is designed to work as you describe.

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

Brett Meyer
March 7, 2014, 5:30 PM

Bulk closing rejected tickets in "resolved" state.

Assignee

Gail Badner

Reporter

lorenzo pergolini

Fix versions

None

Labels

None

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Components

Affects versions

Priority

Major
Configure