-
1. Re: Auditing a Many-To-Many Relation
adamw Jun 17, 2011 3:22 AM (in response to n.mirzadeh)As I said in the PM, you didn't mention what the error actually is
Adam
-
2. Re: Auditing a Many-To-Many Relation
n.mirzadeh Jun 17, 2011 5:19 AM (in response to adamw)The history of my audit-annotation:
1)
@NotAudited
private Set<AddonFile> addonFiles = new HashSet<AddonFile>(0);
The relation is saved.
-------------------------------------------------------
2)
@AuditJoinTable(name="CAMS_X_TYPE_CARD_ADDON_FILE",
inverseJoinColumns={@JoinColumn(name="ID_ADDON_FILE"),
@JoinColumn(referencedColumnName="ID_TYPE_CARD")})
private Set<AddonFile> addonFiles = new HashSet<AddonFile>(0);
Raised this error at the initialization of the listeners
org.hibernate.MappingException: An audited relation from com.bellid.cams.model.CardType.addonFiles to a not audited entity com.bellid.cams.model.AddonFile! Such mapping is possible, but has to be explicitly defined using @Audited(targetAuditMode = NOT_AUDITED).
------------------------------------------------------------
3) The following will cause an error because of insertion of "NULL" into a required field.
@Audited(targetAuditMode=RelationTargetAuditMode.NOT_AUDITED)
@AuditJoinTable(name="CAMS_X_TYPE_CARD_ADDON_FILE",
inverseJoinColumns={@JoinColumn(name="ID_ADDON_FILE"),
@JoinColumn(referencedColumnName="ID_TYPE_CARD")})
private Set<AddonFile> addonFiles = new HashSet<AddonFile>(0);
-
3. Re: Auditing a Many-To-Many Relation
adamw Jun 20, 2011 1:55 PM (in response to n.mirzadeh)First of all, you should consider if the AddonFile should be audited or not. Generally, RelationTargetAuditMode.NOT_AUDITED should only be used when the other side is a dictionary-type entity.
If you are sure you want to use it, I don't quite understand what is the error in the 3) case? Where is the null inserted?
Adam
-
4. Re: Auditing a Many-To-Many Relation
n.mirzadeh Jun 20, 2011 5:17 PM (in response to adamw)Hi Adam,
If you read the error message, it clearly says that AddonFile is not audited! In other words, it is treated as dictionary type entries as you would say. In general, it should be possible to audit any side of a many-to-many relation! Case 2) didn't work. I put case 3) just to show that I've done what the error-message suggested.
So, my question is why I get that error in case 2)?, and what is the correct way to annotated the above relation.
-
5. Re: Auditing a Many-To-Many Relation
adamw Jun 21, 2011 2:25 AM (in response to n.mirzadeh)As the error message says, in such a case (where only one side of a relation is not audited), you should use: @Audited(targetAuditMode=RelationTargetAuditMode.NOT_AUDITED).
So I'm wondering why you get the error and what it exactly is. It is of course possible that Envers has some bug in that area, I just can't see it yet .
Adam