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

Auditing of collections of embeddables only supporting single element changes

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 4.2.0.Final
    • Fix Version/s: 4.2.1, 4.3.0.Beta2
    • Component/s: hibernate-envers
    • Labels:
      None
    • Environment:
      Hibernate: 4.2.0.Final
      DB: any
    • Bug Testcase Reminder (view):

      Bug reports should generally be accompanied by a test case!

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

      Description

      I’ve started to move from our local 3.6.7 branch (https://github.com/kristofferlundberg/hibernate-core/tree/3.6.7.Final_HHH-6613), where support for auditing of collections of embeddables/components is implemented, to Hibernate 4.2.0.Final.

      Sadly it looks like there are some issues regarding the merge.
      The unit tests that I created didn’t cover adding/removing multiple items in a set at once.
      If I had added better coverage in those tests, it would have shown the underlying problem and the reason for why I added the SETORDINAL.

      The secondary table doesn't contain the columns of the embeddable in the primary key since they may be null.
      Not all database vendors allow nulls in the primary key/unique indexes (Microsoft SQL Server in our case), so we need some other kind of value distinguishing the different rows.
      That’s why I added the SETORDINAL, being the ordinal of the element in the change set.

      The current implementation in 4.2.0.Final generates:
      CREATE TABLE embsetent_set_aud
      (
      rev INTEGER NOT NULL,
      revtype TINYINT NOT NULL,
      embeddablesetentity_id INTEGER NOT NULL,
      str1 VARCHAR(255),
      audcomp_description VARCHAR(255),
      audcomp_key VARCHAR(255),
      audcomp_value VARCHAR(255),
      PRIMARY KEY (rev, revtype, embeddablesetentity_id)
      )

      This only allows for one entry per revision type and owning entity for each set.

      When adding the SETORDINAL:

      CREATE TABLE embsetent_set_aud
      (
      rev INTEGER NOT NULL,
      revtype TINYINT NOT NULL,
      embeddablesetentity_id INTEGER NOT NULL,
      setordinal INTEGER NOT NULL,
      str1 VARCHAR(255),
      audcomp_description VARCHAR(255),
      audcomp_key VARCHAR(255),
      audcomp_value VARCHAR(255),
      PRIMARY KEY (rev, revtype, embeddablesetentity_id, setordinal)
      )

      I’ve created a branch based on the 4.2.0.Final tag and added a suggested solution:

      https://github.com/kristofferlundberg/hibernate-core/commit/fb051813ad7f4aa66bfb96886c09bd528832cdcb

        Attachments

          Issue links

            Activity

              People

              • Votes:
                0 Vote for this issue
                Watchers:
                4 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: