Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp
Hi... I'm having a problem getting a simple aggregate class relationship to work in nhibernate. I just started to learn nhibernate.
Anyway, the unit test I ran could not get a reference to the aggregate class when I queried for the LodestarAccount object. In other words, the LodestarCustomer object within the LodestarAccount object had no reference upon return of the hibernate query.
Any thoughts? Also, is there a resource out there for newbies like myself that really explains mapping well foundationally? I found the docs to be more reference-like.
Hibernate version:
nhibernate 2.01 GA
Mapping documents:
LodestarAccount.hbm.xml
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="BusinessDataTransfer" namespace="BusinessDataTransfer" >
<class name="BusinessDataTransfer.LodestarAccount,BusinessDataTransfer" table="HEAP.ACCOUNT">
<id name="UidAccount" column="UIDACCOUNT" type="Int32" unsaved-value="0">
<generator class="native"/>
</id>
<property name="AccountId" column="ACCOUNTID" type="string" not-null="true"/>
<property name="UdcAcctId" column="UDCACCTID" type="string" not-null="false"/>
<component name="Customer" class="BusinessDataTransfer.LodestarCustomer,BusinessDataTransfer">
<property name="Name" />
</component>
</class>
</hibernate-mapping>
LodestarCustomer.hbm.xml
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="BusinessDataTransfer" namespace="BusinessDataTransfer" >
<class
name="BusinessDataTransfer.LodestarCustomer,BusinessDataTransfer"
table="HEAP.CUSTOMER">
<id
name="UidCustomer"
column="UIDCUSTOMER"
type="Int32"
unsaved-value="0">
<generator class="native" />
</id>
<property
name="Name"
column="NAME"
type="string"
not-null="false" />
</class>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():Code:
IDaoFactory daoFactory = new NHibernateDaoFactory();
ILodestarAccountDao accountDao = daoFactory.GetLodestarAccountDao();
LodestarAccount resultAccount = accountDao.GetById(241, false);
Assert.AreEqual("COMED_0489034013", resultAccount.AccountId);
Assert.AreEqual("Lake Forest Hospital - 0489034013", resultAccount.Customer.Name);
Full stack trace of any exception that occurs:Code:
System.NullReferenceException: Object reference not set to an instance of an object.
at CerSoDataLayerTests.NHibernateDaoFactoryTests.CanGetAggregatedLodestarAccount() in NHibernateDaoFactoryTests.cs: line 46
Name and version of the database you are using:Oracle 10g
The generated SQL (show_sql=true):Code:
SELECT lodestarac0_.UIDACCOUNT as UIDACCOUNT2_0_, lodestarac0_.ACCOUNTID as ACCOUNTID2_0_, lodestarac0_.UDCACCTID as UDCACCTID2_0_, lodestarac0_.Name as Name2_0_ FROM HEAP.ACCOUNT lodestarac0_ WHERE lodestarac0_.UIDACCOUNT=:p0; :p0 = '241'
Debug level Hibernate log excerpt:
Problems with Session and transaction handling?
Read this:
http://hibernate.org/42.html
[/list]