Issue Type: Bug Bug
Affects Versions: 4.2.0.Final
Assignee: Unassigned
Components: envers
Created: 10/Apr/13 11:32 PM
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
Project: Hibernate ORM
Priority: Major Major
Reporter: Kristoffer Lundberg
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira