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 table mapping
PostPosted: Mon Nov 26, 2007 12:24 pm 
Newbie

Joined: Mon Nov 26, 2007 12:11 pm
Posts: 1
I see single class to multiple table mapping is a feature on the roadmap for nHibernate, so I am trying to do this the simplest way possible until then.

What are the recommended solutions?

I was hoping I could do something like:

Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
               namespace="Survey.Domain"
               assembly="Survey.Domain"
               default-access="field.camelcase-underscore">
   <class name="Survey">
      <id name="SurveyId">
         <generator class="native" />
      </id>
      <property name="SurveyName" />
      <property name="ExternalId" />
      <property name="IsLive" />
      <property name="Score" />
      <property name="ReviewCount" />

      <loader query-ref="GetSurvey"/>
   </class>

   <sql-query name="GetSurvey">
      <return alias="survey" class="Survey"/>
      <![CDATA[SELECT tbl_survey.SurveyId,
      tbl_survey.SurveyName,
      tbl_survey.ExternalId,
      tbl_survey.IsLive,
      tbl_survey_rating.Score,
      tbl_survey_rating.ReviewCount
      FROM tbl_survey
      LEFT OUTER JOIN tbl_survey_rating ON tbl_survey.ExternalId = tbl_survey_rating.ExternalId]]>
   </sql-query>

</hibernate-mapping>


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 26, 2007 1:22 pm 
Hibernate Team
Hibernate Team

Joined: Tue Jun 13, 2006 11:29 pm
Posts: 315
Location: Calgary, Alberta, Canada
You can use a <one-to-one>; and that's probably the simplest.

If you proceed with the way you outlined (using <loader>), you would also have to use <sql-insert>, <sql-update>, and <sql-delete> to tell NH how to do those operations.

An alternative would be to map to a database view, provided the DBMS you are using allows writable views. With MS SQL, you can create triggers on the view to simulate writable views.

If you don't mind living on the edge a bit, you can check out the source from the trunk. It has the <join> element; although it has a fairly major issue (NH-1059) when applied to a <subclass>.

_________________
Karl Chu


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.