0 Replies Latest reply on Jul 6, 2015 10:36 AM by Ankita Maru

    Hibernate Envers with many-to-one mapping

    Ankita Maru Newbie

      I am using hibernate envers 4.0.1.Final, with Hibernate 4.1.4.Final. I have below entities having relation with each other :

       

      CustomerEntity;

       

      @Entity

      @Table(name = "customer")

      @Audited

      public class CustomerEntity extends TenantEntity implements Serializable

      {

       

          @Id

          @GeneratedValue(strategy = GenerationType.AUTO)

          @Column(name = "Customer_ID", unique = true, nullable = false)

          private Long customerId;

       

         //bi-directional many-to-one association to CustomerNote

          @OneToMany(mappedBy="customer", fetch = FetchType.LAZY, cascade = CascadeType.ALL)

          private List<CustomerNoteEntity> customerNotes;

       

      }

       

      CustomerNoteEntity:

       

      @Entity

      @Table(name="customer_note")

      @Audited

      public class CustomerNoteEntity extends BaseEntity implements Serializable {

        private static final long serialVersionUID = 1L;

       

      //bi-directional many-to-one association to Customer

      @ManyToOne

        @JoinColumn(name="customer_id")

        private CustomerEntity customer;

      }

       

      When I do a insert in CustomerNoteEnitiy, following queries are triggered:

       

      1) insert into customer_note

      2)insert into REVINFO

      3) insert into customer_note_AUD

      4)insert into customer_AUD

       

      When it inserts in customer_AUD, i get

      org.springframework.dao.DataIntegrityViolationException: Column 'customer_creation_datetime' cannot be null.

      All the values to be inserted in the customer_AUD are null. How can hibernate get values for the data to be inserted in the customer_AUD table.

       

      Is there an option that we can audit only the child table (CustomerNote) along with the join column and not the Parent table(Customer)