CodeSmith自动生成NHibernate的数据库访问层

来源:互联网 发布:外卖人8.7 源码 编辑:程序博客网 时间:2024/04/29 23:09

常见问题

1.在调用AbstractNHibernateDao<Supplier, String>.SaveOrUpdate(Supplier supplier)添加数据时提示错误信息“Row

 was updated or deleted by another transaction (or unsaved-value mapping was incorrect)”。

   

答:见"supplier.hbm.xml"文件,CodeSmith模板自动生成*.hbm.xml文件,generator的class属性是"native",

Supplier表,主键是String类型,手动将generator的class修改成"assigned"。其他情况默认值"native",即可。


 文件"supplier.hbm.xml "

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
<class name="CMS.Model.Supplier, CMS.Model" table="supplier">
<id name="Id" type="String" unsaved-value="null">
<column name="SupplierID" length="60" sql-type="varchar" not-null="true" unique="true" index="PRIMARY"/>
<generator class="assigned" />
</id>
<property name="SupplierName" type="String">
<column name="SupplierName" length="135" sql-type="varchar" not-null="true" unique="true" index="SupplierName_UNIQUE"/>
</property>

</class>

</hibernate-mapping> 

0 0
原创粉丝点击