5 Replies Latest reply on Feb 7, 2011 7:15 AM by benpoole

    Envers @OneToMany audit on CREATE(0) but not on DELETE(2)

    benpoole Newbie

      Hi Guys,

       

      I've looked a quite a few similar issues like: http://community.jboss.org/message/580407#580407 but haven't found a solution yet.

       

      An Activity has many Occurences, when an occurence is created the activity_occurence_AUD table is updated correctly with a 0 (create) revision.

       

      However when an occurance is removed the activity_occurence_AUD table is not populated with a 2 (delete) revision.

       

      Activity Entity:

       

      @Entity

      @Table(name = "activity")

      @Audited

      public class Activity implements Serializable {

          private static final long serialVersionUID = 1L;

       

          public static final int[] VALID_PRIORITIES = { 0, 1, 2, 3 };

       

          @Id

          @GeneratedValue(strategy = GenerationType.IDENTITY)

          @Basic(optional = false)

          @Column(name = "id", nullable = false)

          private Long id;

       

          @OneToMany(cascade = CascadeType.ALL, mappedBy = "activity")

          private List<ActivityOccurrence> activityOccurrenceList;

       

      ....

       

      }

       

      ActivityOccurence Entity:

       

      @Entity

      @Table(name = "activity_occurrence")

      @Audited   

      public class ActivityOccurrence implements Comparable<ActivityOccurrence>, Serializable {

          private static final long serialVersionUID = 1L;

          @Id

          @GeneratedValue(strategy = GenerationType.IDENTITY)

          @Basic(optional = false)

          @Column(name = "id", nullable = false)

          private Long id;

       

          @JoinColumn(name = "activity_id", referencedColumnName = "id", nullable = false)

          @ManyToOne(optional = false)

          private Activity activity;

       

      ....

       

      }

       

      hibernate properties:

       

      <entry key="hibernate.ejb.event.post-insert"      value="org.hibernate.ejb.event.EJB3PostInsertEventListener,org.hibernate.envers.event.AuditEventListener" />

      <entry key="hibernate.ejb.event.post-update"      value="org.hibernate.ejb.event.EJB3PostUpdateEventListener,org.hibernate.envers.event.AuditEventListener" />

      <entry key="hibernate.ejb.event.post-delete"      value="org.hibernate.ejb.event.EJB3PostDeleteEventListener,org.hibernate.envers.event.AuditEventListener" />

      <entry key="hibernate.ejb.event.pre-collection-update" value="org.hibernate.envers.event.AuditEventListener" />

      <entry key="hibernate.ejb.event.pre-collection-remove" value="org.hibernate.envers.event.AuditEventListener" />

      <entry key="hibernate.ejb.event.post-collection-recreate" value="org.hibernate.envers.event.AuditEventListener" />

       

       

      Any help would be much appreciated.

       

      It's strange that the update works but the delete doesn't.

      Let me know if I can provide any more information.

       

      Thanks in advance!

       

      Ben