so both B and A are entities, using some inheritance strategy, or B is a @MappedSuperclass?
Either way you're right that it's inconsistent, annotating a class should be the same as annotating all properties.
To prevent users from "accidentally" auditing a subclass, maybe an exception should be thrown. But then, there should be a way to audit only the properties from the superclass, but none from the subclass.
What do you think, what should be the correct behavior? :)
Also, could you create a JIRA bug for that?
Hi Adam, thanks for your time.
I tried 2 cases:Superclass A mark as @MappedSuperclass.
Subclass strategy mapping.
About the correct behavior in this case, I think that the NotAuditedException would be the best option...
I m thinking in big hierarchies in which you want to audit only one branch. In this cases you should annotate the complete branch from the leaf to the root for auditing the branch you need. And the non annotated branch/leaf will not be audited.
At the current time in envers, this restriction is not applied; then if you annotates the root at fields/getters level and save an entity from the non audited branch/leaf , you could be auditing it too.
Do you understand my point?
So, if you want to audit a subclass, you must mark it as auditable. Otherwise it is not audited.
What do you think is the best option?
Thanks again. Hernan.
Yes, I think I agree, as you say, if you want to audit a subclass, it must be marked auditable, but only the properties from superclasses that are either implictly or explicitly annotated as @Audited are audited.
Could you create a JIRA bug for that? :)
Before creating the jiira issue I re-test all cases. That is, all hierarchy mapping strategies and the @MappedSubclass too.
I did a mistake with the tests before, because the only case that presents this behavior is when there is a @MappedSuperclass in the superclass A.
So, my original explanation only applies to this case.
So it doesn't work properly with @MappedSuperclass not audited and the subclass not? :)
Hi Adam! Sorry about my mistake.
Here is the case. Suppose B is a subclass of A.
The subclass B is @Entity and is not audited.
The superclass A is @MappedSuperclass.
The differents behaviors are:
- If A has @Audited at class level, envers does not generate audit info when saving an instance of B.
- If A has @Audited at field/getter level, envers generates audit info when saving an instance of B.
Thanks again. Hernan.
That's clearly a bug :) Please report it in JIRA. And thanks for the detailed investigation.