-->
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.  [ 2 posts ] 
Author Message
 Post subject: single class to multiple tables (<join> mapping elemen
PostPosted: Fri Jul 08, 2005 9:54 am 
Newbie

Joined: Fri Jul 08, 2005 9:44 am
Posts: 1
Hello:
I was wondering on the possibility of nhibernate supporting a single class to multiple table mappings, as indicated in some hibernate 3.0 documentation.
The basic issue is trying to map subclasses (GenericProduct, SpecialProduct, AnotherSpecialProduct) to a table structure where most attributes are stored in columns in the GenericProduct table, and then attributes specific to SpecialProduct are stored in a foreign-key-related table (and attributes specific to AnotherSpecialProduct are stored in the AnotherSpecialProduct table, which is related back to the GenericProduct table by a foreign key).
One possibility in code is to use, in the case of the SpecialProduct subclass, a value/data object that is itself composed of two value/data objects whose properties are mapped back to their respective GenericProduct and SpecialProduct table columns... but this adds complexity to the data layer that I would rather leave to hibernate if at all possible.

So... any timelines on nhibernate support for the join mapping element, or any other suggestions on this kind of table to object mapping?

Thanks.

DR


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 08, 2005 11:32 am 
Expert
Expert

Joined: Fri May 13, 2005 5:56 pm
Posts: 308
Location: Santa Barbara, California, USA
I may not be understanding your question fully, but I think NH already supports something like this using joined-subclass. I have a polymorphic Asset class (abstract) that has concrete implementation classes (File, URI). Most attributes are stored in the Asset Table with specific data stored in each subclass table (File, URI). It is very simple for now, but here is a sample of my mapping file:

Code:
<?xml version="1.0" encoding="utf-8" ?>

<hibernate-mapping   xmlns="urn:nhibernate-mapping-2.0"
            namespace="AMA.Core.Domain.Assets"
            assembly="AMA.Core">

<class   name="Asset"
   table="Asset"
   dynamic-update="true">
      
   <jcs-cache usage="read-write" />

   <id name="id" column="AssetID" type="Guid" unsaved-value="{00000000-0000-0000-0000-000000000000}" access="field">
      <generator class="guid" />
   </id>
      
   <version name="version" column="Version" type="Int32" unsaved-value="-1" access="field" />
      
   <many-to-one   name="Owner"
            class="AMA.Core.Domain.Member"
            column="OwnerID"
            not-null="true"
            access="nosetter.camelcase" />
      
   <property name="Title" column="Title" type="String" not-null="true" />
   <property name="DateCreated" column="DateCreated" type="DateTime" not-null="true" update="false" access="nosetter.camelcase" />
   <property name="LastUpdate" column="LastUpdate" type="DateTime" not-null="true" />
   <property name="IsArchived" column="IsArchived" type="Boolean" not-null="true" />
            
   <bag   name="MemberAssets"
      table="MemberAsset"
      cascade="all-delete-orphan"
      inverse="true"
      lazy="true"
      access="nosetter.camelcase">
   
      <key column="AssetID" />
      <one-to-many class="MemberAsset" />
   </bag>
      
   <joined-subclass   name="File"
               table="`File`"
               dynamic-update="true">
         
      <key column="FileID" />
      <many-to-one   name="FileType"
               column="FileTypeID"
               class="FileType"
               not-null="true"
               outer-join="true"
               cascade="none" />

      <property name="FileName" column="`FileName`" type="String" not-null="true" />
      <property name="Content" column="Content" type="BinaryBlob" not-null="false" />
         
   </joined-subclass>
      
   <joined-subclass   name="URI"   
               table="URI"
               dynamic-update="true">
         
      <key column="UriID" />
         
      <property name="Path" column="Path" type="String" not-null="true" />
         
   </joined-subclass>
      
</class>

</hibernate-mapping>


In this situation, the PK of the File and URI tables are FKs to the PK of the Asset table.

hth,

-devon


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