Reputation: 2783
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
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#
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>
Upvotes: 0
Views: 2031
Reputation: 123901
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.
The trick is that NHibernate files, embedded resources, have two suffixes: .hbm.xml. The configuration like this:
<mapping assembly="CaseMgr.Model" />
Works with convention: search embedded resources with the extension .hbm.xml. So, if your new file is
It must be
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
EXTENDED
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:
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)
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)
Upvotes: 2