3 Replies Latest reply on Nov 17, 2012 3:55 PM by Adam Warski

    Problem with deleting Revision Entity (on delete cascade)

    berger710 Newbie

      Hi,

      sorry if this problem already has been discussed.

      I found out that a revision entry can't be deleted with a given EntityManager.

      I'm using hibernate 4.0.1-Final and JBoss 7.1.1:

       

      
      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;
      

       

       

      Is there any other possibility to configure hibernate envers so that all referenced audited entities are cascaded on delete?

       

       

      Thank you for your help.