I'm away from VS currently so I cant really test your example but...
Yes. Collections of components should work fine since v 1.6.

I dont know fluent nhibernate so if you can reproduce this error with only nh 
core (and envers), please report it to the jira (eg use hbm mapping).
Also, dont really know why you involve the collection in your entitiy's 
equals/gethashcode impl - that _might_ be the issue.


Sent from Samsung Mobile


-------- Original message --------
From: João Alexandre Toledo
Date:2014/07/28 1:15 AM (GMT+01:00)
To: [email protected]
Subject: [nhusers] Envers: error auditing entity with Set property

Hi,

I have a class named Body; it has a property named Items, which is a set of 
BodyItem. I use NHibernate and Envers to persist that to the database and 
generate audit data.
When I try to persist an instance of Body which has only one BodyItem in 
Body.Items, everything works, and audit data is also recorded. But when I add 
two different items to Body.Items and try to persist it, an exception is 
throwed:

NHibernate.NonUniqueObjectException: a different object with the same 
identifier value was already associated with the session: 
System.Collections.Generic.Dictionary`2[System.String,System.Object], of 
entity: ttbl_items_log

If I mark Body.Items with [NotAudited], then I can persist data normally, but 
(obviously) the audit data for the items is not recorded.

Can you please help me with that? Am I doing some mapping the wrong way? Or 
Envers simply can't audit this kind of relationship?

Those are simplified versions of the classes,. All of them can be found here: 
https://gist.github.com/jalexandretoledo/52146ba0cd0326e97b0d


[Audited]
public class Body
{
  public virtual Int32 Id { get; set; }
  public virtual String Name { get; set; }

  // [NotAudited]  <-- it will work if this is uncommented, but then I don't 
have audit data for Items
  public virtual ICG.ISet<BodyItem> Items { get; set; }
  public Body()
  {
    Items = new ICG.HashedSet<BodyItem>();
  }
}



public class BodyItem
{
  public virtual DateTime Date { get; set; }
  public virtual Byte ByteValue { get; set; }
  public virtual Decimal DecimalValue { get; set; }

  ...
}



This is how they are mapped:


internal class BodyMap : ClassMap<Body>
{
  internal BodyMap()
  {
    Table("ttbl_body");
    Id(x => x.Id).Column("id_body").GeneratedBy.Identity();
    Map(x => x.Name).Column("nm_body");

    HasMany(x => 
x.Items).Table("ttbl_items").KeyColumn("id_body_item").Component(
       m =>
       {
         m.Map(x => x.Date).Column("dt_item").Not.Nullable();
         m.Map(x => x.ByteValue).Column("nr_item").Not.Nullable();
         m.Map(x => x.DecimalValue).Column("vl_item").Not.Nullable();
       }
     ).Cascade.AllDeleteOrphan();
  }
}




Thanks in advance.

João


--
You received this message because you are subscribed to the Google Groups 
"nhusers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to 
[email protected]<mailto:[email protected]>.
To post to this group, send email to 
[email protected]<mailto:[email protected]>.
Visit this group at http://groups.google.com/group/nhusers.
For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"nhusers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/nhusers.
For more options, visit https://groups.google.com/d/optout.

Reply via email to