-->
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.  [ 3 posts ] 
Author Message
 Post subject: 1 object, 2 tables with different primary key names.
PostPosted: Fri Jun 03, 2005 8:02 am 
I am about to start evaluating NHibernate but to save time could someone answer me this?

I've got 2 tables in a legacy database.

Table1(PrimaryKey1, Field1),
Table2(PrimaryKey2, Field2).

There is a one to one relationship between PrimaryKey1 and PrimaryKey2.

I would like to map to one object. Is this possible?

Thanks in advance
Tim


Top
  
 
 Post subject:
PostPosted: Fri Jun 03, 2005 3:56 pm 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
No, unfortunately it's not possible with NHibernate. You can only map it as a one-to-one association.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 06, 2005 5:32 am 
Thanks for the reply.

Its seems I can do what I want with a joined-subclass.

Code:
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
   <class name="NH_FF_TestApp.Party, NH-FF-TestApp" table="tblParty874a">
      <id name="Wid" column="PartyWID" type="String" length="20">
         <generator class="assigned" />
      </id>
      <property name="MainName"/>
      <!--
      <property name="Password" column="aPassword" type="String" length="20" />
      <property name="EmailAddress" type="String" length="40" />
      <property name="LastLogon" type="DateTime" />
      -->
   </class>
   <joined-subclass name="NH_FF_TestApp.ClientJoint, NH-FF-TestApp" extends="NH_FF_TestApp.Party, NH-FF-TestApp"
      table="tblClientJoint909">
      
      <key column="WID"/>
      <property name="SelfWID"  column="SelfWID" type="String" length="20"/>
      <property name="Comment"/>      
   </joined-subclass>
</hibernate-mapping>


I do have another question.

If I try to use the Party object I get an error
Quote:
Unhandled Exception: NHibernate.ADOException: problem in find ---> System.Data.OleDb.OleDbException: IErrorInfo.GetDescription failed with E_FAIL(0x80004005).

Code:
         Configuration cfg = new Configuration();
         cfg.AddAssembly("NH-FF-TestApp");

         NH.ISessionFactory factory = cfg.BuildSessionFactory();
         _session = factory.OpenSession();
//         IList recentUsers = _session.CreateCriteria(typeof(ClientJoint)).List();
//
//         foreach(ClientJoint user in recentUsers)
//         {
//            Debug.WriteLine(user.Wid);
//         }
         IList recentUsers = _session.CreateCriteria(typeof(Party)).List();

         foreach(Party user in recentUsers)
         {
            Debug.WriteLine(user.Wid);
         }



Should I be able to do this?

Best wishes
Tim


Top
  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.