-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 
Author Message
 Post subject: Cannot get one-to-one component class reference
PostPosted: Sat Jan 24, 2009 11:45 am 
Newbie

Joined: Sat Jan 24, 2009 11:19 am
Posts: 3
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]


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jan 25, 2009 10:14 am 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
Looks like you need a one-to-one and not a component. Components are used if the data is in the same table.

On LoadstartAccount:

<one-to-one name="Customer" .... />

Have a look at http://nhforge.org/doc/nh/en/index.html#mapping-declaration-onetoone.

There are a few books available for Hibernate. You can use them to start. Concepts and mapping are almost the same like in NHibernate. And there should be a preview available for "NHibernate in Action".

_________________
--Wolfgang


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 26, 2009 10:34 am 
Newbie

Joined: Sat Jan 24, 2009 11:19 am
Posts: 3
Hi Wolfgang,

Can you tell me where I might be able to preview 'NHibernate in Action' ? I've been patiently waiting for it to come out and do plan to purchase it.

I'd very much like to get an idea of its contents.

Thank you for your help. Looking closer at the documentation, I realize now the difference between 'Component' and 'One-to-one'. It took a bit of fiddling but I think I have the hang of it.

- Peter


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 26, 2009 11:37 am 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
The eBook seems to be officialy available:

http://www.manning.com/kuate/

_________________
--Wolfgang


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.