Rejected
Details
Assignee
Former userFormer user(Deactivated)Reporter
lorenzo pergolinilorenzo pergoliniComponents
Affects versions
Priority
Major
Details
Details
Assignee
Former user
Former user(Deactivated)Reporter
lorenzo pergolini
lorenzo pergoliniComponents
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
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 /