Uploaded image for project: 'Hibernate ORM'
  1. HHH-8320

Envers store_data_at_delete does not populate entity id on delete revision

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Rejected
    • Affects Version/s: 4.2.1
    • Fix Version/s: None
    • Component/s: hibernate-envers
    • Labels:
    • Bug Testcase Reminder (view):

      Bug reports should generally be accompanied by a test case!

    • Last commented by a user?:
      true
    • Sprint:

      Description

      First posted from the Hibernate Envers community forum:
      https://community.jboss.org/message/823516#823516

      Hibernate Envers setup with 'store_data_at_delete' = 'true' in order to provide an additional revision when an entity is deleted. In Hibernate 4.2.1.Final, when a mapping entity is deleted, Hibernate Envers attempts to insert a deletion revision record into the appropriate audit table, but does not populate the insert statement with the id of the entity that is being deleted.

      The delete revision record was not being inserted at all in Hibernate 4.1.12.Final, but after viewing HHH-8087 Closed and upgrading, this issue was observed.

      The use case I had was the following with all entities having an @Audited annotation.

      • User table - User metadata
      • User group table - User group metadata. Deleting a user group deletes all user group member associations via cascade.
      • User group member table - A mapping table to associate users to one or more user groups.

      1. Create user
      2. Create user group
      3. Add user to user group (Envers inserts an 'ADD (0)' revision for user group member.)
      4. Delete user group which also cascades to delete associated user group member records (Envers inserts a 'DEL (2)' revision for user group member with no user group member id.

      The user group member audit table schema is below...

      Table "user_group_member_aud"
          Column     |   Type   | Modifiers
      ---------------+----------+-----------
      rev           | integer  | not null
      user_group_id | uuid     | not null
      user_id       | uuid     | not null
      revtype       | smallint |
      id            | uuid     | not null
      Indexes:
          "user_group_member_aud_pkey" PRIMARY KEY, btree (id, rev)
      

      The hibernate log shows as follows as the insert is done with no id. The db constraint prevents the insertion due to the not null constraint on the audit table id column.

      Hibernate:
          insert
          into
              user_group_member_AUD
              (REVTYPE, REV, user_group_id, user_id)
          values
              (?, ?, ?, ?)
      2013-06-14 09:57:10,430 WARN [SqlExceptionHelper] - SQL Error: 0, SQLState: 23502
      2013-06-14 09:57:10,430 ERROR [SqlExceptionHelper] - Batch entry 0 insert into user_group_member_AUD (REVTYPE, REV, user_group_id, user_id) values ('2', '4900', 'b15f1cee-1eea-4a51-a9df-4fb90f8eb95c', '361d0717-7d8a-4af9-9b17-871190052d1c') was aborted.  Call getNextException to see the cause.
      2013-06-14 09:57:10,431 WARN [SqlExceptionHelper] - SQL Error: 0, SQLState: 23502
      2013-06-14 09:57:10,431 ERROR [SqlExceptionHelper] - ERROR: null value in column "id" violates not-null constraint
      

        Attachments

          Issue links

            Activity

              People

              • Votes:
                1 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: