We're updating the issue view to help you get more done. 

Auditing of collections of embeddables only supporting single element changes

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

Environment

Hibernate: 4.2.0.Final
DB: any

Status

Assignee

Lukasz Antoniak

Reporter

Kristoffer Lundberg

Fix versions

Labels

None

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Components

Affects versions

4.2.0.Final

Priority

Major