-
1. Re: Can I mark an field as not audited even though the object of the field is an audited entity?
sacortes Jan 30, 2013 11:16 AM (in response to scdf)Hi,
I need the same thing... Have you found some good solution?
By the moment, in my particular case, that is "Showing historical data", my only solution is using duplicate clases (and duplicate mappings with the same tables) with a limited amount of attributes (only showed), but i don't like it too much:
@Audited
class Foo2
@Audited(targetAuditMode = RelationTargetAuditMode.NOT_AUDITED)
Bar2 latestBar
// Not audited
class Bar2
Thanks in advance,
Sebastian
-
2. Re: Can I mark an field as not audited even though the object of the field is an audited entity?
adamw Jan 30, 2013 4:01 PM (in response to scdf)Just annotate the field as @NotAudited, note though that upon retrieving historical data, the field's value will be null. There is no way to get historical data which points to the "latest" version.
Adam
-
3. Re: Can I mark an field as not audited even though the object of the field is an audited entity?
scdf Jan 30, 2013 5:49 PM (in response to adamw)"There is no way to get historical data which points to the "latest" version."
Right, so in other words, there is no way to do what I want to do.
In the end I decided to just attach to the historical version of the data. In my particular use-case it's conceptually incorrect but won't make a different to the users. Perhaps for other people a workaround would be do it yourself manually-- take the historical version and then use that to load the latest version.
-
4. Re: Can I mark an field as not audited even though the object of the field is an audited entity?
hltbdivl Feb 28, 2013 9:57 PM (in response to adamw)I've run into a very similar issue, and was confused by the documentation. Here is my data model:
{code}
@Audited
public class Foo {
...
@Audited(targetAuditMode = RelationTargetAuditMode.NOT_AUDITED)
private Bar latestBar;
}
public class Bar {
....
@Audited
private String someField;
}
{code}
Note the difference: only one field in Bar is audited.
Now, the relevant snippet of the documentation says:
{quote}
If you want to audit a relation, where the target entity is not audited (that is the case for example with dictionary-like entities, which don't change and don't have to be audited), just annotate it with
@Audited(targetAuditMode = RelationTargetAuditMode.NOT_AUDITED)
. Then, when reading historic versions of your entity, the relation will always point to the "current" related entity.{quote}
So I expected that querying for Foo, then traversing foo.latestBar would yield, as the name suggests, the "current" related Bar. What's actually happening is that I get a Bar that's entirely null save for its ID and its someField. Meaning, Bar's proxy initialization is being satisfied by historical data, not by current data.
Reading the docs again, I see that they qualify the behavior with "where the target entity is not audited". They don't explicitly state the behavior for when it is audited, and I think they should: you'll only get current data if none of the target entity's fields are audited.
Come to think of it, I don't see how targetAuditMode is useful. The presence or lack of an @Audited() annotation on the target entity already determines whether that entity is audited; doesn't that make targetAuditMode redundant?
On a related note, another section of the docs say:
{quote}
-
5. Re: Can I mark an field as not audited even though the object of the field is an audited entity?
adamw Mar 1, 2013 2:35 PM (in response to hltbdivl)In your model, Bar is audited (an entity is audited if at least one field is audited), so you shouldn't use RelationTargetAuditMode.NOT_AUDITED. It won't work for audited entities, probably hence the weird behavior you are seeing.
Adam
-
6. Re: Can I mark an field as not audited even though the object of the field is an audited entity?
hltbdivl Mar 1, 2013 2:47 PM (in response to adamw)Adam Warski wrote:
In your model, Bar is audited (an entity is audited if at least one field is audited), so you shouldn't use RelationTargetAuditMode.NOT_AUDITED. It won't work for audited entities, probably hence the weird behavior you are seeing.
Adam
Agreed, I see this now. I was just hoping the documentation could be changed to clarify this. Though my original presumption still stands: targetAuditMode seems redundant to me, because @Audited on the target entity will already determine whether that entity gets audited or not.
-
7. Re: Can I mark an field as not audited even though the object of the field is an audited entity?
adamw Mar 2, 2013 2:03 AM (in response to hltbdivl)Docs always need improving, it would be great if things can be explained more clearly; maybe you could create a pull request on github? (you can edit it straight from the browser).
By default Envers throws an exception if there's an audited relation from an audited entity to a non-audited entity, as in most cases this is a mapping error; targetAuditMode is to specify an exception to this.
Adam
-
8. Re: Can I mark an field as not audited even though the object of the field is an audited entity?
pelu Mar 18, 2013 7:11 PM (in response to adamw)I'm also desperately trying to find some kind of tolerable solution that would allow me to have a link from an audited entity to the current version of another audited entity. So this seems to be quite a common need. In my case both of the entities are part of an inheritance hierarchy and I need to perform Envers queries against them which return possibly hundreds of results, so duplicating classes or changing references after the queries have already returned wrong references are far from ideal solutions.
So if somebody has found some sort of annotation combination, hack or even a way to patch Envers to handle this, I would really like to hear about it.
-
9. Re: Can I mark an field as not audited even though the object of the field is an audited entity?
stigrv Apr 11, 2013 9:37 AM (in response to pelu)If not a change in how targetAuditMode is read by the library, then a new annotation that lets you link to the current version of an entity would be desired.
-
10. Re: Can I mark an field as not audited even though the object of the field is an audited entity?
an_sush Apr 30, 2013 3:01 PM (in response to pelu)I am looking for a similar solution as pelu is expecting. Anyone has solution for the same?
-
11. Re: Can I mark an field as not audited even though the object of the field is an audited entity?
adamw May 23, 2013 11:39 AM (in response to an_sush)Create an issue in JIRA and vote (unless the feature request is not already there).
Adam