说也奇怪,添加和查找就能成功,就删除不能(更新还写好),执行删除时出现“
Could not compile the mapping document: fuck.Model.Customer.hbm.xml”异常,
映射言论是<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
<class name="fuck.Model.Customer,fuck.Model" table="Customer">
<id name="CustomerId" type="Int32" unsaved-value="null">
<column name="CustomerId" length="4" sql-type="int" not-null="true" unique="true" index="PK_Customer"/>
<generator class="native" />
</id>
<property name="FirstName" type="String">
<column name="FirstName" length="50" sql-type="varchar" not-null="true"/>
</property>
<property name="LastName" type="String">
<column name="LastName" length="50" sql-type="varchar" not-null="true"/>
</property>
<property name="Version" type="int">
<column name="Version" length="4" sql-type="int" not-null="true"/>
</property>
<!--一对多关系:Customer有一个或多个Orders-->
<set name="Order" table="Order" generic="true" inverse="true">
<key column="CustomerId" foreign-key="FK_Order_Customer"/>
<one-to-many class="fuck.Model.Order,fuck.Model"/>
</set>
</class>
</hibernate-mapping>
删除事件是
private void buttonDelect_Click(object sender, EventArgs e)
{
int path =Int32.Parse( this.textBoxCustomerId.Text);
Customer customer = reference.Find_Customer(path);
reference.Delect(customer);
}
public Customer Find_Customer(int i)
{
Customer customer;
customer = operation.FindCustomerMessage(i);
return customer;
}
public Customer FindCustomerMessage(int I)
{
ISession session = ISession_Factory.OpenSession("fuck.Model");
transaction =session.BeginTransaction();
Customer customer;
try
{
customer =(Customer) session.Get(typeof(Customer),I);
transaction.Commit();
}
catch (Exception e)
{
transaction.Rollback();
throw e;
}
finally
{
session.Close();
}
return customer;
}
同问