0

我添加了一个新表、.hbm.xml文件和class现有应用程序。其他表格中的数据也显示在页面上。

对于这个新表数据不会保存和显示。

NHibernate忽略它。我没有收到任何错误消息。我也更改了tablehbm.xml文件中的值,但没有错误。但是,如果我更改table其他文件,应用程序会抛出异常。看起来它不知道新文件。我将此文件制作为Embedded Resource. 我正在使用VS 2010,MVCOracleC#

这是xml和类。提前致谢。

<?xml version="1.0" encoding="utf-8" ?>
<class name="CaseMgr.Model.BusinessObjects.PatLiverPeld, CaseMgr.Model" table="TGLN.PAT_LIVER_PELD" lazy="true">
  <id name="Id" column="PLP_ID" unsaved-value="0">
    <generator class="sequence">
       <param name="sequence">PLP_SEQ</param>        
    </generator>
 </id>   
<timestamp name="ModifyDate" column="MODIFY_DATE" generated="always"></timestamp>
<property name="CreateDate" column="CREATE_DATE" update="false"></property>
<property name="CreateBy" column="CREATE_BY" update="false" />
<property name="ModifyBy" column="MODIFY_BY" update="false" />
<property name="TestDate" column="PELD_TEST_DATE" />
<property name="ExpDate" column="PELD_EXP_DATE" />
<property name="SerumBilirubin" column="SERUM_BILIRUBIN" />
<property name="Inr" column="INR" />
<property name="Albumin" column="ALBUMIN" />
<property name="GrowthFailure" column="GROWTH_FAILURE" type="YesNo" />
<property name="Peld" column="PELD" />

<many-to-one name="PatRegister" column="PATR_ID" class="PatRegister" />

<bag name="PatLiverSmcs" lazy="true" inverse="true" >
  <key column="PATR_ID"></key>
  <one-to-many class="PatLiverSmc"></one-to-many>
</bag>
<bag name="PatLiverSmcHiss" lazy="true" cascade="all-delete-orphan" inverse="true" >
  <key column="PATR_ID"></key>
  <one-to-many class="PatLiverSmcHis"></one-to-many>
</bag>

public partial class PatLiverPeld : BusinessBase<decimal>
{
    private DateTime _createDate = new DateTime();
    private string _createBy =string.Empty;
    private string _modifyBy = string.Empty;
    private DateTime _modifyDate = new DateTime();
    private DateTime? _testDate ;
    private DateTime? _expDate ;
    private double? _serumBilirubin ;
    private double? _inr ;
    private double? _albumin ;
    private bool _growthFailure ;
    private double? _peld ;

    private PatRegister _patRegister = null;

    private IList<PatLiverSmc> _patLiverSmcs = new List<PatLiverSmc>();
    private IList<PatLiverSmcHis> _patLiverSmcHiss = new List<PatLiverSmcHis>();



    public PatLiverPeld(){ }

    public override int GetHashCode()
    {
        System.Text.StringBuilder sb = new System.Text.StringBuilder();

        sb.Append(this.GetType().FullName);
        sb.Append(_createDate);
        sb.Append(_createBy);
        sb.Append(_modifyBy);
        sb.Append(_modifyDate);
        sb.Append(_testDate);
        sb.Append(_expDate);
        sb.Append(_serumBilirubin);
        sb.Append(_inr);            
        sb.Append(_albumin);
        sb.Append(_growthFailure);
        sb.Append(_peld);
        return sb.ToString().GetHashCode();            
    }



    public virtual DateTime CreateDate 
    {
        get { return _createDate; }
        set { _createDate = value; } 
    }

    public virtual string CreateBy 
    {
        get { return _createBy; }
        set { _createBy = value; } 
    }

    public virtual string ModifyBy 
    {
        get { return _modifyBy; }
        set { _modifyBy = value; }
    }

    public virtual DateTime ModifyDate 
    {
        get { return _modifyDate; }
        set { _modifyDate = value; }
    }

    public virtual DateTime? TestDate 
    {
        get { return _testDate; }
        set { _testDate = value; }
    }

    public virtual DateTime? ExpDate 
    {
        get { return _expDate; }
        set { _expDate = value; }

    }


    public virtual double? SerumBilirubin 
    {
        get { return _serumBilirubin; }
        set { _serumBilirubin = value; }

    }

    public virtual double? Inr
    {
        get { return _inr; }
        set { _inr = value; }
    }

    public virtual double? Albumin 
    {
        get { return _albumin; }
        set { _albumin = value; } 
    }

    public virtual bool GrowthFailure 
    {
        get { return _growthFailure; }
        set { _growthFailure = value; }
    }

    public virtual double? Peld
    {
        get { return _peld; }
        set { _peld = value; }

    }


    public virtual PatRegister PatRegister
    {
        get { return _patRegister; }
        set { _patRegister = value; }
    }

    public virtual IList<PatLiverSmc> PatLiverSmcs
    {
        get { return _patLiverSmcs; }
        set { _patLiverSmcs = value; }

    }

    public virtual IList<PatLiverSmcHis> PatLiverSmcHiss 
    {
        get { return _patLiverSmcHiss; }
        set { _patLiverSmcHiss = value; }
    }

    public virtual bool IsDataExpired
    {
        get
        {
            return (ExpDate.HasValue && ExpDate.Value <= DateTime.Today);
        }
    }

    //public virtual bool IsPatPeld
    //{
    //    get { return this.PatRegister.Pat.Age <= LiverSmcConst.PAEDIATRIC_PELD_AGE; }
    //}
}

Web.Config

 <hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
 <session-factory>

   <property name="connection.provider">CaseMgr.Web.Dao.SvcConnectionProvider,CaseMgr.Web</property>
  <!--<property name="connection.provider">CaseMgr.Model.Base.NHConnectionProvider, CaseMgr.Model</property>-->
  <property name="connection.driver_class">NHibernate.Driver.OracleDataClientDriver</property>
  <property name="connection.connection_string_name">OraConnStr</property>
  <property name="show_sql">false</property>
  <property name="dialect">NHibernate.Dialect.Oracle9iDialect</property>
  <property name="hbm2ddl.keywords">none</property>
  <property name="query.substitutions">true 'Y', false 'N'</property>
  <property name="proxyfactory.factory_class">NHibernate.ByteCode.LinFu.ProxyFactoryFactory, NHibernate.ByteCode.LinFu</property>
  <property name="cache.provider_class">CaseMgr.OracleCache.OraCacheProvider, CaseMgr.OracleCache</property>
  <property name="cache.use_second_level_cache">true</property>
  <property name="cache.use_query_cache">true</property>
   <mapping assembly="CaseMgr.Model" />
  </session-factory>
  </hibernate-configuration>
4

1 回答 1

2

我最近遇到了和你类似的问题。在 VS 2012 中,文件重命名的工作方式如下:1)通过单击选择.hbm.xml文件... 2)选择文件后缀之前的部分。3) 键入新名称,而后缀不变。

诀窍是 NHibernate 文件,嵌入式资源,有两个后缀:.hbm.xml。像这样的配置:

<mapping assembly="CaseMgr.Model" />

符合约定:搜索扩展名为.hbm.xml的嵌入式资源。所以,如果你的新文件是

  • 我的新文件.xml

肯定是

  • 我的新文件 .hbm xml

在我的情况下,丢失的.hbm是 NHibernate 根本不知道该文件的原因,如果它是错误的,也不会引发异常......但它没有加载并且不可用

扩展

如果我正确地理解了你的场景:一个 VS 项目(库),许多 .hbm.xml 文件,都是嵌入式资源,除了一个之外,所有的都在工作。

如果我正确地重现了您的问题,您应该:

运行 IL Spy 以检查 dll 是否包含所有预期
的嵌入式资源 运行如下测试:

var factory = ... //get your NHibernate factory
var entityType = typeof(CaseMgr.Model.BusinessObjects.PatLiverPeld);
var persister = factory.GetClassMetadata(entityType) as AbstractEntityPersister;
Assert.IsTrue(persister != null)

如果您会看到资源,并且没有持久性...尝试将您的映射移动到现有的工作文件(一个 .hbm.xml 文件中的两个类)。由于在“worng”配置类映射期间缺少异常(如问题中所述),几乎不会发生任何其他情况

于 2013-08-09T03:55:20.303 回答