-->
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: How to write custom HQL for joined-subclasses?
PostPosted: Wed Jun 04, 2008 8:16 pm 
Newbie

Joined: Wed Jun 04, 2008 8:03 pm
Posts: 1
Location: United Kingdom
Hello,

I've been trying to figure this out, so any help would be much appreciated...

I've got a World Item:

Code:
   <class
      name="WorldItem"
      table="WORLD_ITEMS"
   >
      <meta attribute="sync-DAO">false</meta>

      <id
         name="worlditemid"
         type="integer"
         column="worlditemid"
      >
         <generator class="increment" />
      </id>

      <many-to-one name="item" class="Item" column="itemid" unique="true" fetch="join"/>
      
      <property
         name="quantity"
         column="quantity"
         type="integer"
      />
      
   </class>   


That is a link between a world and an item.
My item is extended by Structure and Unit

Code:
   <class name="Item" table="ITEMS">
      <id column="itemid" name="Itemid" type="integer">
         <!--<generator class="org.hibernate.id.TableHiLoGenerator">
                    <param name="table">NEXTNUMBER</param>
            <param name="column">NEXTNUM</param>
               </generator>-->
         <generator class="increment" /> <!-- -->
      </id>
      <property
         column="resourceFiveMaintenance"
         length="10"
         name="ResourceFiveMaintenance"
         not-null="false"
         type="integer"
       />
      <property
         column="level"
         length="10"
         name="Level"
         not-null="false"
         type="integer"
       />
      <property
         column="itemname"
         length="255"
         name="Itemname"
         not-null="true"
         type="string"
       />
      <property
         column="itemType"
         length="50"
         name="ItemType"
         not-null="false"
         type="string"
       />
      <property
         column="resourceTwoMaintenance"
         length="10"
         name="ResourceTwoMaintenance"
         not-null="false"
         type="integer"
       />
      <property
         column="resourceThreeMaintenance"
         length="10"
         name="ResourceThreeMaintenance"
         not-null="false"
         type="integer"
       />
      <property
         column="hitpoints"
         length="10"
         name="Hitpoints"
         not-null="false"
         type="integer"
       />
      <property
         column="resourceThreeCost"
         length="10"
         name="ResourceThreeCost"
         not-null="false"
         type="integer"
       />
      <property
         column="resourceFiveCost"
         length="10"
         name="ResourceFiveCost"
         not-null="false"
         type="integer"
       />
      <property
         column="resourceFourMaintenance"
         length="10"
         name="ResourceFourMaintenance"
         not-null="false"
         type="integer"
       />
      <property
         column="resourceTwoCost"
         length="10"
         name="ResourceTwoCost"
         not-null="false"
         type="integer"
       />
      <property
         column="resourceOneCost"
         length="10"
         name="ResourceOneCost"
         not-null="false"
         type="integer"
       />
      <property
         column="timeToBuild"
         length="10"
         name="TimeToBuild"
         not-null="false"
         type="integer"
       />
      <property
         column="description"
         length="1024"
         name="Description"
         not-null="false"
         type="string"
       />
      <property
         column="levelLadder"
         length="255"
         name="LevelLadder"
         not-null="false"
         type="string"
       />
      <property
         column="resourceOneMaintenance"
         length="10"
         name="ResourceOneMaintenance"
         not-null="false"
         type="integer"
       />
      <property
         column="resourceFourCost"
         length="10"
         name="ResourceFourCost"
         not-null="false"
         type="integer"
       />
      <property
         column="scoreValue"
         length="10"
         name="ScoreValue"
         not-null="false"
         type="integer"
       />
       <property
         column="sortOrder"
         name="sortOrder"
         not-null="false"
         type="integer"
       />
      
       <joined-subclass name="ns.game.objects.Structure" table="STRUCTURES">
         <key column="itemid"/>
         <property name="GeneratesResourceOne" column="generatesResourceOne" type="integer" not-null="false" length="10"/>
        <property name="GeneratesResourceTwo" column="generatesResourceTwo" type="integer" not-null="false"   length="10"/>
        <property   name="GeneratesResourceThree" column="generatesResourceThree" type="integer" not-null="false" length="10"/>
        <property name="GeneratesResourceFour" column="generatesResourceFour" type="integer" not-null="false" length="10"   />
        <property   name="GeneratesResourceFive" column="generatesResourceFive"   type="integer" not-null="false"   length="10" />
        <property   name="Capacity"   column="capacity" type="integer" not-null="false" length="10"/>
        <property   name="structureSize" column="size" type="integer" not-null="false" length="10"/>
        <property name="unitTypesAllowed"   column="unittypesallowed" type="string" not-null="false" length="512"/>
        <property   name="Sight" column="sight"   type="integer" not-null="false"   length="10"/>
        <property   name="Attack" column="attack" type="integer" not-null="false" length="10"/>
        <property   name="Defense" column="defense"   type="integer" not-null="false"   length="10"/>
        <property   name="WorkersRequired" column="workers_required" type="integer"   not-null="false" length="10"/>
        <property name="Active" column="active" type="boolean" not-null="false" length="50" />
        <property   name="Initiative" column="initiative" type="integer" not-null="false" length="10"/>
       </joined-subclass>
       <joined-subclass name="ns.game.objects.Unit" table="UNITS">
         <key column="itemid"/>
         <property name="Closecombat" column="closecombat" type="integer" not-null="false" length="10"/>
         <property name="Weaponattack" column="weaponattack" type="integer" not-null="false" length="10"/>
         <property name="Clusterattack" column="clusterattack" type="integer" not-null="false" length="10"/>
         <property name="Armor" column="armor" type="integer" not-null="false" length="10"/>
         <property name="Defense" column="defense" type="integer" not-null="false" length="10"/>
         <property name="Initiative" column="initiative" type="integer" not-null="false" length="10"/>
         <property name="Stealth" column="stealth" type="integer" not-null="false" length="10"/>
         <property name="Explorerange" column="explorerange" type="integer" not-null="false" length="10"/>
         <property name="Speed" column="speed" type="integer" not-null="false" length="10"/>
         <property name="Movement" column="movement" type="integer" not-null="false" length="10"/>
         <property name="Rank" column="rank" type="integer" not-null="false" length="10"/>
         <property name="Range" column="range" type="integer" not-null="false" length="10"/>
         <property name="Teamwork" column="teamwork" type="integer" not-null="false" length="10"/>
         <property name="UnitType"   column="unittype" type="string" not-null="false" length="255"/>
       </joined-subclass>
   </class>


Now, what I've been trying to do, is to get the total size of all structures in a specific world... so thru SQL, I wrote the following query but can't seem to make something similar in HQL:

Code:
select sum(s.size) as total from structures s, world_items wi
where s.itemid = wi.itemid
and wi.worldid = 52


I've gone thru many iterations of what I might do in HQL and run into so many errors, it's not even worth mentioning...

Any one have any suggestions about how to do this?

I imagine it should be something like:

select sum(structureSize) from Structure s, Item i, WorldItem wi where s.itemid = i.itemid and i.itemid = wi.itemid and wi.worldid = 52.

However, that says it can't find the property itemid of structure... But doesn't that exist as a property or because it's a "foreign key" it doesn't count as a property?

I tried joining on the tables but I couldn't figure it out...
Thanks!!


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