I call this function on my objects when they need to be initialized again:
public virtual void Initialize()
{
if (!HibernateSessionManager.Instance.GetSession().Contains(this)) {
try
{
HibernateSessionManager.Instance.GetSession()
.Lock(this, NHibernate.LockMode.None);
}
catch (NonUniqueObjectException e) { }
}
}
I thought I can prevent initializing something twice with checking Contains(this), but it happens sometimes that Lock(this, NHibernate.LockMode.None) throws a NonUniqueObjectException. So far I ignore it because it works, but I’d like to know the reason and a better way to Lock my objects.
Best regards, Expecto
the problem was a completely different – contains checks for equality by reference if I don’t override
Equals(). Now it works with the code from my question!