我在现有应用程序中添加了一个新表.hbm.xml
文件和class
。其他表中的数据也显示在页面上。
对于此新表格,不会保存和显示数据。
NHibernate
忽略它。我没有收到任何错误消息。我还更改了新table
文件中的hbm.xml
值,但没有错误。但是,如果我在其他文件中更改table
,则应用程序会抛出异常。看起来它不知道新文件。我将此文件设为Embedded Resource
。我正在使用VS 2010
,MVC
和Oracle
以及C#
这是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>
答案 0 :(得分:2)
我和你最近面临的类似问题。在VS 2012中,文件重命名的工作方式如下:1)通过单击选择 .hbm.xml 文件... 2)选择文件后缀之前的部分。 3)键入新名称,而后缀不变。
诀窍是NHibernate文件嵌入式资源有两个后缀:.hbm.xml。配置如下:
<mapping assembly="CaseMgr.Model" />
适用于惯例:搜索扩展名为 .hbm.xml 的嵌入资源。所以,如果您的新文件是
一定是
缺少的 .hbm 在我的情况下是原因,为什么NHibernate根本不知道该文件,并且如果它出错则没有抛出异常......但它没有被加载不可用
EXTENDED
如果我的方案正确:一个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”配置类映射期间缺少异常(如问题中所述)