也nhibernate会遇到问题,还好找到原因了

晚了很多才开始学习nhibernate,也是整了好久,遇到些问题,记录下来,

1.nhibernate提示错误
      The dialect was not set. Set the property hibernate.dialect.
解决:
因为我用了两个项目文件,一个为类库项目,一个为WEB项目,我将以下这段,以nhibernate.cfg.xml 放在了类库项目中,其实要把这段放在web.config文件中.
  <?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
        
<class name="pb.testdal.Db.users, testdal1" table="users">
            
<LogonID name="LogonID" column="LogonID" type="String(20)">
                
<generator class="assigned" />
            
</LogonID>
                
<property name="Name" type="String" column="Name(40)"/>
            
<property name="Password" type="String" column="Password(20)"/>
            
<property name="EmailAddress" type="String" column="EmailAddress(20)"/>
            
<property name="LastLogon" type="DateTime" column="LastLogon" />
        
</class>
</hibernate-mapping>
      2.nhibernate提示错误
identiifier of an instance of DataAccess.User altered from 13(System.Int16) to 13(System.Int32
解决:
因为SQL SERVER 2000 建立INT长度为4,所以为int32型,将Int16改成INT32就对了
  <?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
        
<class name="pb.testdal.Db.users, testdal1" table="users">
            
<LogonID name="LogonID" column="LogonID" type="Int16">
                
<generator class="assigned" />
            
</LogonID>
            
            
<property name="Name" type="String" column="Name(40)"/>
            
<property name="Password" type="String" column="Password(20)"/>
            
<property name="EmailAddress" type="String" column="EmailAddress(20)"/>
            
<property name="LastLogon" type="DateTime" column="LastLogon" />
        
</class>
</hibernate-mapping>
3.nhibernate提示错误
列无效
解决:
察看hbm.xml 映射文件,column="name"/>是不是与数据库中的列名对应

在写映射文件是关键注意三个地方
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
        
<class name="pb.testdal.Db.users, testdal1" table="users">
            
<LogonID name="LogonID" column="LogonID" type="String(20)">
                
<generator class="assigned" />
            
</LogonID>
            
            
<property name="Name" type="String" column="Name(40)"/>
            
<property name="Password" type="String" column="Password(20)"/>
            
<property name="EmailAddress" type="String" column="EmailAddress(20)"/>
            
<property name="LastLogon" type="DateTime" column="LastLogon" />
        
</class>
</hibernate-mapping>
1.DataAccess.User,处,与类对应的命名空间是否一致,大小写也要一致
2.type="String(25)"处,字段 长度的定义是否这样定义
3. column="Password"/处,列名也数据库中的字段是否一致


posted on 2005-10-21 18:08  王跃军  阅读(2024)  评论(2编辑  收藏  举报