説明: 現在の Web 要求を実行中に、ハンドルされていない例外が発生しました。エラーに関する詳細および例外の発生場所については、スタック トレースを参照してください。
例外の詳細: NHibernate.StaleStateException: Unexpected row count: 0; expected: 1
ソース エラー:
行 112: catch (Exception ex)
行 113: {
行 114: throw ex;
行 115: }
行 116: }
ソース ファイル: c:\Documents and Settings\zhangxiuyan\My Documents\Visual Studio 2005\WebSites\Web\UserManager.aspx.cs 行: 114
スタック トレース:
[StaleStateException: Unexpected row count: 0; expected: 1]
NHibernateWebDemo.Web.UserManager.wbtn_Save_Click(Object sender, EventArgs e) in c:\Documents and Settings\zhangxiuyan\My Documents\Visual Studio 2005\WebSites\Web\UserManager.aspx.cs:114
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +96
System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +116
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +31
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +32
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +72
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3839
表结构为Groupu GroupID PK
GroupName
Users LogonID PK
Name varchar(40),
Password varchar(20),
EmailAddress varchar(40) ,
LastLogon datetime
GroupID FK
user.hbm.xml文件如下
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
<class name="NHibernateWebDemo.Model.User, NHibernateWebDemo.Model" table="Users">
<id name="Id" type="String" unsaved-value="null">
<column name="LogonID" length="20" sql-type="varchar" not-null="true" unique="true" index="PK__Users__2C3393D0"/>
<generator class="assigned" />
</id>
<property name="UserName" type="String">
<column name="Name" length="40" sql-type="varchar" not-null="false"/>
</property>
<property name="Password" type="String">
<column name="Password" length="20" sql-type="varchar" not-null="false"/>
</property>
<property name="EmailAddress" type="String">
<column name="EmailAddress" length="40" sql-type="varchar" not-null="false"/>
</property>
<property name="LastLogon" type="DateTime">
<column name="LastLogon" sql-type="datetime" not-null="false"/>
</property>
<many-to-one name="Groupu" class="NHibernateWebDemo.Model.Groupu, NHibernateWebDemo.Model">
<column name="GroupID" length="20" sql-type="varchar" not-null="true"/>
</many-to-one>
</class>
</hibernate-mapping>
USER.CS文件如下
using System;
using System.Collections;
namespace NHibernateWebDemo.Model
{
#region User
/// <summary>
/// User object for NHibernate mapped table 'Users'.
/// </summary>
public class User
{
#region Member Variables
protected string _id;
protected string _name;
protected string _password;
protected string _emailAddress;
protected DateTime _lastLogon;
protected Groupu _groupu;
#endregion
#region Constructors
public User() { }
public User( string name, string password, string emailAddress, DateTime lastLogon, Groupu groupu )
{
this._name = name;
this._password = password;
this._emailAddress = emailAddress;
this._lastLogon = lastLogon;
this._groupu = groupu;
}
#endregion
#region Public Properties
public virtual string Id
{
get {return _id;}
set
{
if ( value != null && value.Length > 20)
throw new ArgumentOutOfRangeException("Invalid value for Id", value, value.ToString());
_id = value;
}
}
public virtual string UserName
{
get { return _name; }
set
{
if ( value != null && value.Length > 40)
throw new ArgumentOutOfRangeException("Invalid value for Name", value, value.ToString());
_name = value;
}
}
public virtual string Password
{
get { return _password; }
set
{
if ( value != null && value.Length > 20)
throw new ArgumentOutOfRangeException("Invalid value for Password", value, value.ToString());
_password = value;
}
}
public virtual string EmailAddress
{
get { return _emailAddress; }
set
{
if ( value != null && value.Length > 40)
throw new ArgumentOutOfRangeException("Invalid value for EmailAddress", value, value.ToString());
_emailAddress = value;
}
}
public virtual DateTime LastLogon
{
get { return _lastLogon; }
set { _lastLogon = value; }
}
public virtual Groupu Groupu
{
get { return _groupu; }
set { _groupu = value; }
}
#endregion
}
#endregion
}
Groupu.hbm.xml文件如下
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
<class name="NHibernateWebDemo.Model.Groupu, NHibernateWebDemo.Model" table="Groupu">
<id name="GroupID" type="String" unsaved-value="null">
<column name="GroupID" length="20" sql-type="varchar" not-null="true" unique="true" index="PK_Groupu"/>
<generator class="assigned" />
</id>
<property name="GroupName" type="String">
<column name="GroupName" length="20" sql-type="varchar" not-null="true"/>
</property>
<bag name="Userses" inverse="true" lazy="true" cascade="all-delete-orphan">
<key column="GroupID"/>
<one-to-many class="NHibernateWebDemo.Model.User, NHibernateWebDemo.Model"/>
</bag>
</class>
</hibernate-mapping>
Groupu.cs文件如下
using System;
using System.Collections;
namespace NHibernateWebDemo.Model
{
#region Groupu
/// <summary>
/// Groupu object for NHibernate mapped table 'Groupu'.
/// </summary>
public class Groupu
{
#region Member Variables
protected string _id;
protected string _groupName;
protected IList _userses;
#endregion
#region Constructors
public Groupu() { }
public Groupu( string groupName )
{
this._groupName = groupName;
}
#endregion
#region Public Properties
public virtual string GroupID
{
get {return _id;}
set
{
if ( value != null && value.Length > 20)
throw new ArgumentOutOfRangeException("Invalid value for Id", value, value.ToString());
_id = value;
}
}
public virtual string GroupName
{
get { return _groupName; }
set
{
if ( value != null && value.Length > 20)
throw new ArgumentOutOfRangeException("Invalid value for GroupName", value, value.ToString());
_groupName = value;
}
}
public virtual IList Userses
{
get
{
if (_userses==null)
{
_userses = new ArrayList();
}
return _userses;
}
set { _userses = value; }
}
#endregion
}
#endregion
}
汗一个,,初学NHibernate,自己对比了很久,可能配置文件有问题,可不知道哪出问题了.网上似乎也没有见到有1对多表联的例子,研究过这东东的高手来看一下,不胜感激.
6 个解决方案
#1
沙发
外包?
外包?
#2
是的啊,,,,唉,高手没有回答我啊,,
继续等
继续等
#3
欢迎访问www.chinadacs.cn
#4
欢迎访问 http://www.chinadacs.cn
#5
asdfsadf
#6
http://www.cnblogs.com/jillzhang/archive/2007/03/23/685750.html
这里有配置详解。
这里有配置详解。
#1
沙发
外包?
外包?
#2
是的啊,,,,唉,高手没有回答我啊,,
继续等
继续等
#3
欢迎访问www.chinadacs.cn
#4
欢迎访问 http://www.chinadacs.cn
#5
asdfsadf
#6
http://www.cnblogs.com/jillzhang/archive/2007/03/23/685750.html
这里有配置详解。
这里有配置详解。