Deleting Revision Entity (on delete cascade)

Description

List<Object[]> results = query.getResultList();
for (Object[] result : results)
{
CustomRevisionEntity rev = (CustomRevisionEntity)result[1];
em.remove(rev);
}

This deletion causes a violation of foreign key constraint for every Audit-table of each entity annotated with @Audited.

I think that's because the the Audit-table for each entity and the RevisionChanges-table are created and altered by hbm2dll with these statements:
"create table REVCHANGES(RevId number(19,0) not null,EntityName varchar2(255 char));"

"alter table REVCHANGES add constraint FKD33F46C4B65ED994 foreign key (RevId) references REVINFO;"

To work this around I alter all these tables again by adding "ON DELETE CASCADE" to the foreign key constraint, e.g.:
"alter table REVCHANGES drop constraint FKD33F46C4B65ED994;"
"alter table REVCHANGES add constraint FKD33F46C4B65ED994 foreign key (RevId) references REVINFO ON DELETE CASCADE;"

There should be a possibility to set the cascade for an @Audited Entity, maybe in the annotation.

Environment

None

Assignee

Lukasz Antoniak

Reporter

Philipp Berger

Fix versions

Labels

backPortable

None

Suitable for new contributors

Yes, likely

Requires Release Note

None

Pull Request

None

backportDecision

None

Components

Affects versions

Priority

Major
Configure