-->
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.  [ 1 post ] 
Author Message
 Post subject: Question: Using Hql to query subclass properties...
PostPosted: Thu May 11, 2006 8:47 am 
Regular
Regular

Joined: Tue Feb 07, 2006 4:27 pm
Posts: 69
I have a Location class that has a many-to-many relationship with a LegalLandDescription class.

The LegalLandDescription class has 2 concrete subclasses Nts and Dls. The Nts and Dls each have a unique set of mapped properties.

I'd like to write a query that will include both Nts and Dls entities.

I know that I can create a view that will do this for me, but I'm hopeful
that is is not necessary. Another option I believe is to have the entire class retrieved as part of the result-set.

If someone with more experience could put together a quick sample of wha the HQL would look like that would be great.

Thanks in advance



Here are my mapping documents:

Location
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0" assembly="Model.Domain" namespace="Model.Domain">
   <class name="Location" table="LOCATION">

      <id name="LocationId" column="LOCATION_ID" type="Int64" unsaved-value="0">
         <generator class="native"/>
      </id>
   
      <many-to-one name="LocationPosition" column="LOCATION_POSITION_TYPE_ID" class="LocationPosition" />

    <bag name="ProjectClasses" table="PROJECT_CLASS_LOCATION" cascade="all" inverse="true" outer-join="true">
      <key column="PROJECT_CLASS_ID" />
      <many-to-many column="location_id"
                    class="Model.Domain.ProjectClass, Model.Domain"  />
    </bag>
   
    <bag name="LegalLandDescriptions" table="LOCATION_LEGAL_LAND_DESCRIPTION_XREF" cascade="all" outer-join="true">
      <key column="LOCATION_ID" />
      <many-to-many column="LEGAL_LAND_DESCRIPTION_ID"
                    class="Model.Domain.LegalLandDescription, Model.Domain"  />
    </bag>
   
    <bag name="Coordinates" table="LOCATION_COORDINATE_XREF" cascade="all" outer-join="true">
      <key column="LOCATION_ID"/>
      <many-to-many column="COORDINATE_ID"
                    class="Model.Domain.Coordinate, Model.Domain"/>
    </bag>
  </class>
</hibernate-mapping>


LegalLandDescription
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0" assembly="Model.Domain" namespace="Model.Domain">
  <class name="LegalLandDescription" table="LEGAL_LAND_DESCRIPTION">

    <id name="Id" column="LEGAL_LAND_DESCRIPTION_ID" type="Int64" unsaved-value="0">
      <generator class="native"/>
    </id>

    <bag name="Locations" table="LOCATION_LEGAL_LAND_DESCRIPTION_XREF" inverse="true"
         cascade="all" outer-join="true">     
      <key column="LEGAL_LAND_DESCRIPTION_ID" />     
      <many-to-many column="LOCATION_ID"
                    class="Model.Domain.Location, Model.Domain"/>     
    </bag>
   
  </class>
</hibernate-mapping>


Dls
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0"
                   assembly="Model.Domain" namespace="Model.Domain">
 
  <joined-subclass name="DlsLocation" table="DLS_LOCATION" extends="LegalLandDescription"
                   dynamic-insert="true" dynamic-update="true">

      <key column="DLS_LOCATION_ID"/>
   
      <property column="LSD" type="Int32" name="Lsd" />
      <property column="SEC" type="Int32" name="Sec" />
      <property column="TWP" type="Int32" name="Twp" not-null="true" />
      <property column="RGE" type="Int32" name="Rge" not-null="true" />
      <property column="MER" type="Int32" name="Mer" not-null="true" />
      
   </joined-subclass>
</hibernate-mapping>


Nts
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0" assembly="Model.Domain" namespace="Model.Domain">

    <joined-subclass name="NtsLocation" table="NTS_LOCATION"
                     extends="LegalLandDescription" dynamic-insert="true" dynamic-update="true">

      <key column="NTS_LOCATION_ID"/>
      <property column="QTR" type="Char" name="Qtr" length="1" />
      <property column="UNIT" type="Int32" name="Unit" />
      <property column="BLOCK" type="Char" name="Block" length="1" />
      <property column="MAP" type="Int32"  name="Map"/>
      <property column="SUB" type="Char"  name="Sub" length="1"/>
      <property column="Sheet" type="Int32" name="Sheet"/>

    </joined-subclass>
</hibernate-mapping>
[/b][/code]


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

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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.