NHibernate忽略hbm.xml文件 [英] NHibernate ignores the hbm.xml files

查看:64
本文介绍了NHibernate忽略hbm.xml文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I added a new table, .hbm.xml file and class to existing application. There is data from other tables as well displayed on the page.

对于此新表,不会保存和显示数据.

For this new table data is not saved and displayed.

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

NHibernate ignores it. I don't get any error message. I also change the table value in the new hbm.xml file, but there is no error. But, if I change table in other files, application throws exception. Looks like it is not aware of the new file. I made this file as Embedded Resource. I'm using VS 2010, MVC and Oracle and C#

这是xml和类.预先感谢.

And here is the xml and class. Thanks in advance.

<?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>

推荐答案

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

The similar issue as you, I have faced recently. And it was in VS 2012, where file re-naming works like, 1) selecting .hbm.xml file by clicking on it... 2) the part before file suffix is selected. 3) type new name, while suffix is unchanged.

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

The trick is that NHibernate files, embedded resources, have two suffixes: .hbm.xml. The configuration like this:

<mapping assembly="CaseMgr.Model" />

符合约定:使用扩展名 .hbm.xml 搜索嵌入式资源.因此,如果您的新文件是

Works with convention: search embedded resources with the extension .hbm.xml. So, if your new file is

  • MyNewFile.xml

必须是

  • MyNewfile .hbm. xml
  • MyNewfile .hbm. xml

缺少的 .hbm 是NHibernate根本不了解该文件的原因,并且如果错误是不会抛出异常的.不可用

the missing .hbm was in my case the reason, why NHibernate did not know about that file at all, and no exception was thrown if it was wrong... but it was not loaded and not available

扩展

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

If I get your scenario correctly: One VS project(library), many .hbm.xml files, all are embedded resources, all are working but one.

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

If I reproduce your issue correctly you should:

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

run IL Spy to check that the dll contains all expected embedded resources
run a test like:

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"配置类映射过程中缺少异常(如问题所述),几乎不会发生任何其他情况

In case that you'll see resource, and there is NO persister... try to move your mapping to existing working file (two classes in one .hbm.xml file). Any other case could hardly happen, because of missing exceptions during the "worng" config class mappings (as stated in the question)

这篇关于NHibernate忽略hbm.xml文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆