views:

124

answers:

1

Hi,

I have entity User with one-to-many relationship to UserToUserCategories. When I load user from database, do not change it and than flush the session, NHibernate will performs UPDATE of the user and increment it's version. It seems to me as unwanted behaviour, imagine that I load hundred of users and NHibernate would update them all when flushing.

public abstract class EntityBase
{
    public virtual Guid Id { get; set; }
    public virtual int Version { get; set; }
}

public class User : EntityBase
{
    public virtual IList<UserToUserCategory> UserToUserCategories { get; set; }
}

public class EntityBaseMap<T> : ClassMap<T> where T : EntityBase
{
    public EntityBaseMap()
    {
        this.OptimisticLock.Version();
        this.DynamicUpdate();
        this.Id(t => t.Id);
        this.Version(t => t.Version);
    }
}

public class UserMap : EntityBaseMap<User>
{
    public UserMap()
    {
        this.HasMany(u => u.UserToUserCategories)
            .NotFound.Ignore()
            .Cascade.All()
            .LazyLoad()
            .AsBag()
            .WithTableName("UserToUserCategory");
    }
}


session = SessionSource.CreateSession();
var user = (from u in session.Linq<User>() select u).FirstOrDefault();
session.Flush(); // here NHibernate does UPDATE statement of user's version

Is this mapping incorrect? What am I missing?

A: 

If someone would search for such issue, there is answer: http://groups.google.com/group/nhusers/browse_thread/thread/9459d4e16581209

Steve