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.
|