Envers Map<Enum, Entity> not auditing correctly

Description

Hello
I think I discovered a bug in envers while using a Map<enum, entity>. Envers does not produce the KEY column in the database and also forgets the additional Update query during auditing. It might also just be a configuration issue so I'm posting the related model and mappings:

While the operationDetails table contains the column operationdetails_KEY the corresponding audit table does not. From what I can see there is neither an audit join table created. (probably that is the issue?)

The system runs fine in general. I just discovered this issue while trying to integrate Javers to be able to build diffs from two audit query results. As the key-information is missing we end up with a map containing ONE null key with one OperationDetails.

Please let me know if you need anything more.

Environment

None

Activity

Show:
Chris Cranford
June 9, 2017, 5:05 PM
Edited

Envers does not presently have support for @MapKeyEnumerated which is why you ran into this problem.

There is a workaround assuming you can afford a small model change in order to accomplish the same thing but using @MapKey until we offer support for the other annotation. The workaround is to add a property in your OperationDetails class that is your enum type and then rather than using @MapKeyEnumerated you use @MapKey(name = "yourEnumProperty"). This will force Envers to add the column and your model will no longer contain null values as you've seen.

ToDelete
June 10, 2017, 2:21 PM

Hello Chris

Yes this is what I have done now. It's just a shame that we have to take care of that value in two places now
(As a nice side effect we are saving some additional update queries at least.)

As a general note I find it rather unexpected that there is not even a warning about this. Is Envers completely unaware of this annotation?
I just found out "by accident, luckily before going live with the system. If we would not have checked the tables / queries this would have been in production as is, resulting in wrong history. I will now check all history structures.
I would be nice if there is at least a warning output.

Chris Cranford
June 10, 2017, 9:38 PM
Edited

As a general note I find it rather unexpected that there is not even a warning about this. Is Envers completely unaware of this annotation?

For this particular annotation, that's correct. Envers was aware of @MapKey but just didn't have native support for @MapKeyEnumerated unfortunately.

In fact, there are still several annotations and mapping configurations that Envers just cannot yet support for several reasons. Some of them are because the integration between ORM and Envers is based on HBM and there isn't always a direct correlation between some of the newer JPA specification features and HBM. This is certainly a personal focus throughout the Envers 6.x release stream. Many of those which aren't yet supported have open feature requests such as @Where, @WhereJoinTable, @Sort and its derivatives, and @Index.

If you do find others, please don't hesitate to open jira issues for.

Assignee

Chris Cranford

Reporter

ToDelete

Fix versions

Labels

None

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

backportDecision

None

Components

Affects versions

Priority

Critical
Configure