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: mapping
PostPosted: Thu Apr 05, 2007 9:28 am 
Newbie

Joined: Tue Mar 27, 2007 6:30 am
Posts: 12
I am muddling my way through NHibernate and was wondering if it is possible to map an objecy across multiple tables.

For example, I have inherited a data structure with a customer table and an address table.

A customer can only have one address, so would like to map it into one object that combines the data from both tables.

can this be mapped?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 05, 2007 10:03 am 
Newbie

Joined: Tue Apr 03, 2007 11:29 am
Posts: 4
Two to do this :
-> the worst : using a bag and composite-element
-> or using joined-subclass (cf. NHibernate reference documentation, Chapter 8 )

Here is an example :


Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" namespace="Dppr.Biologie.Transport" assembly="Dppr.Biologie">
   <class name="Resultat" table="T_RESULTAT" lazy="false">
      <id name="Identifiant" column="RES_ID_N" type="Int32" unsaved-value="0">
         <generator class="native"/>
      </id>
      <many-to-one column="TES_ID_N" class="Test" name="Test" unique="true" />
      <joined-subclass name="ResultatTexte" table="T_RESULTAT_TEXTE">
         <key column="RES_ID_N" />
         <property column="RET_VALEUR_C" type="String" name="Valeur" />
      </joined-subclass>
      <joined-subclass name="ResultatNumerique" table="T_RESULTAT_NUMERIQUE">
         <key column="RES_ID_N" />
         <property column="REN_VALEUR_N" type="Double" name="Valeur" />
      </joined-subclass>
      <joined-subclass name="ResultatCode" table="T_RESULTAT_CODE">
         <key column="RES_ID_N" />
         <property column="REC_CODE_C" type="String" name="Code" />
         <property column="REC_LIBELLE_C" type="String" name="Libelle" />
         <property column="REC_TABLE_C" type="String" name="Table" />
      </joined-subclass>
   </class>
</hibernate-mapping>


Top
 Profile  
 
 Post subject: Re: mapping
PostPosted: Thu Apr 05, 2007 11:11 am 
Regular
Regular

Joined: Sun Jan 21, 2007 4:33 pm
Posts: 65
garfield wrote:
I am muddling my way through NHibernate and was wondering if it is possible to map an objecy across multiple tables.

For example, I have inherited a data structure with a customer table and an address table.

A customer can only have one address, so would like to map it into one object that combines the data from both tables.

can this be mapped?


Question: Why not map it as a one-to-one relationship? The end result is essentially the same, you just end up creating an Address object whose id points to Customer.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 05, 2007 11:29 am 
Newbie

Joined: Tue Apr 03, 2007 11:29 am
Posts: 4
If you use a one-to-one relationship you should have 2 hbm files and i think that joined-subclass are less constrained than one-to-one properties.


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.