NHibernate:无状态会话错误消息无法获取代理

我正在使用nHibernate无状态会话来获取对象,更新一个属性并将对象保存回数据库。

我一直收到错误信息:

无状态会话无法获取代理

我有类似的代码在别处工作,所以我无法弄清楚为什么这不起作用。 有谁知道问题可能是什么?

我正在尝试更新ScreenLockVersion属性。

制图:

                          

码:

 public class Screen : BaseDomain { private string screenName; private string subScreenName; private Screen parent; private IList childScreens = new List(); private IList affectedScreens = new List(); private Guid screenLockID; private int screenLockVersion; private bool screenLockRequired; private LastModified lastModified; private Identity identity; private ApplicationName application; protected Screen() { this.parent = null; this.screenLockRequired = false; } ///  /// Create new parent screen ///  /// parent screenname public Screen(string screenName, ApplicationName application) { this.screenName = screenName; this.subScreenName = null; this.parent = null; this.application = application; } ///  /// Create new subscreen ///  /// parent screen name /// subscreen name /// reference to parent screen public Screen(string screenName, string subScreenName, Screen parent, ApplicationName application) { this.screenName = screenName; this.subScreenName = subScreenName; this.application = application; this.parent = parent; } #region Properties public virtual IList AffectedScreens { get { return affectedScreens; } set { affectedScreens = value; } } public virtual Screen Parent { get { return parent; } set { parent = value; } } public virtual IList ChildScreens { get { return childScreens; } set { childScreens = value; } } public virtual string ScreenName { get { return screenName; } set { screenName = value; } } public virtual string SubScreenName { get { return subScreenName; } set { subScreenName = value; } } public virtual Guid ScreenLockID { get { return screenLockID; } set { screenLockID = value; } } public virtual int ScreenLockVersion { get { return screenLockVersion; } set { screenLockVersion = value; } } public virtual bool ScreenLockRequired { get { if (parent != null) return parent.ScreenLockRequired; else return screenLockRequired; } set { screenLockRequired = value; } } public virtual LastModified LastModified { get { return lastModified; } set { lastModified = value; } } protected internal virtual Identity Identity { get { return identity; } set { identity = value; } } public virtual ApplicationName Application { get { return application; } set { application = value; } } #endregion #region Methods public override string ToString() { return ScreenName + SubScreenName; } public override bool Equals(object obj) { Screen other = obj as Screen; if (other == null) return false; if (string.IsNullOrEmpty(SubScreenName)) { if(string.IsNullOrEmpty(other.SubScreenName)) return ScreenName.Equals(other.ScreenName) && Application.Equals(other.Application); else return false; } else if (string.IsNullOrEmpty(other.SubScreenName)) return false; else return ScreenName.Equals(other.ScreenName) && SubScreenName.Equals(other.SubScreenName) && Application.Equals(other.Application); } public override int GetHashCode() { if(SubScreenName == null) return ScreenName.GetHashCode() ^ Application.GetHashCode(); else return ScreenName.GetHashCode() ^ SubScreenName.GetHashCode() ^ Application.GetHashCode(); } #endregion } 

无状态会话不支持延迟加载。 您需要尽早加载Screen实体(在当前仅加载代理的同一查询中)。