I have an entity class with an @ElementCollection Map<String, String> property.
Due to application requirements, the map value must support unlimited length strings. I have annotated the entity class accordingly so that the resulting table, in MySQL, has a value column of type longtext.
When I try to add Envers auditing to my class (using Hibernate version 4.2.8), the default DDL generated to create the audit table (xxx_aud) tries to define a primary key that includes both the map key and the map value. MySQL does not allow a longtext column to be included in a primary key, so the DDL fails.
It appears that the reason Envers wants to include the map value in the key has to do with how map value changes are handled. In this case Envers generates two audit rows, one for removing the old value and one for adding the new value. These two rows have the same rev ID and the same map key, but different values for the map value, AND different values for the revision type (revtype).
So, as a workaround, I manually created the audit table using the revision type (revtype) column instead of the map value as part of the primary key. So far, at least, this seems to work.
Does anyone see any problems with this workaround? And if not, wouldn't it be a better approach for Envers to use by default? Given that the revtype is always the same datatype (int) but the map value datatype may vary by application, it would seem to make more sense. Or am I missing some possible situation where two audit rows might be inserted with the same rev, revtype, entity key, and map key?
Thanks,
Jon
|