-->
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: How to filter a query according to its instance type?
PostPosted: Wed Aug 06, 2008 4:13 pm 
Newbie

Joined: Wed Aug 06, 2008 4:00 pm
Posts: 4
Hello,

I have a problem with an HQL Query. I would like to know if we can filter a query with the type of instance such as:

Code:
from SuperClass c where instanceOf(c)=instance


For example, I have a super class Transaction. StockTransaction, TransferTransaction and ThirdTransaction are children of Transaction. ScheduledThirdTransaction is children of ThirdTransaction:

I would like to select all Transaction except ScheduledThirdTransaction, such as:


Code:
from Transaction t where instanceOf(t) != ScheduledThirdTransaction


I hope i was enough explicit. If not, please tell me and I will re-explain. I also hope it is possible to do that because I really didn't find anything on the web

Thanks for your help


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 06, 2008 4:43 pm 
Expert
Expert

Joined: Wed Mar 03, 2004 6:35 am
Posts: 1240
Location: Lund, Sweden
The special property ".class" can be used to access the discriminator column. Eg. something like:

Code:
from Transaction t where t.class <> ScheduledThirdTransaction


See http://www.hibernate.org/hib_docs/v3/re ... yhql-where for more information.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 07, 2008 2:05 am 
Newbie

Joined: Wed Aug 06, 2008 4:00 pm
Posts: 4
Thanks for your help. I have already seen this kind of stuff but it didn't work since I am not using discriminator value. I am using joined-subclass. Here is my actual mapping:

Code:
<hibernate-mapping>

    <class name="net.persofin.transactions.Transaction" lazy="false" table="TRANS">
        <id name="id" column="TRS_ID">
            <generator class="increment"/>
        </id>       
       
        <property name="memo" column="MEMO"/>
        <property name="executionDate" column="EXEDATE" />
        <property name="amount" column="AMOUNT" />
        <property name="type" column="TYPE" />
        <property name="assetFactor" column="ASSET_FACTOR" />       
        <many-to-one name="account" class="net.persofin.accounts.Account" column="ACC_ID"/>       
        <joined-subclass name="net.persofin.transactions.TransferTransaction" lazy="false"   table="TRANSFER">
               <key column="TRANS_ID"/>
                <many-to-one name="linkedTrans"   column="TRANS_TRANS_ID"/>
               <many-to-one name="accountFrom"   column="TRANS_ACC_ID"/>                  
        </joined-subclass>
        <joined-subclass name="net.persofin.transactions.ThirdTransaction" lazy="false"   table="THIRDTRANS">
               <key column="THIRDTR_ID"/>
                <many-to-one name="third"  column="TIR_ID"/> 
                <many-to-one name="cat"  column="CAT_ID"/>                         
        </joined-subclass>
        <joined-subclass name="net.persofin.transactions.StockTransaction" lazy="false"   table="STOCKTRANS">
           <key column="STOCKTR_ID"/>
                <many-to-one name="stock"  column="STK_ID"/> 
                <property name="commissions"  column="COMMISSIONS"/>
                <property name="unitPrice"  column="UNIT_PRICE"/>
                <property name="qty"  column="QTY"/>                         
        </joined-subclass>
       
    </class>
   <class name="net.persofin.transactions.ScheduledThirdTransaction" lazy="false" table="SCHD_THIRDTRANS">
      <id name="id" column="SCHDTR_ID">
            <generator class="increment"/>
        </id>
                  <property name="memo" column="MEMO"/>
                   <many-to-one name="account" class="net.persofin.accounts.Account" column="ACC_ID"/>
                  <property name="executionDate" column="EXEDATE" />
                   <property name="amount" column="AMOUNT" />
                   <property name="type" column="TYPE" />
                 <property name="assetFactor" column="ASSET_FACTOR" />   
                 <many-to-one name="third"  column="TIR_ID"/> 
                    <many-to-one name="cat"  column="CAT_ID"/> 
                   <property name="nextExecutionDate" column="NEXT_EXE_DATE"/>
                   <property name="frequency" column="FREQUENCY"/>
                   <property name="scale" column="SCALE"/>
                   <property name="active" column="ACTIVE"/>
   </class>
</hibernate-mapping>


And I get the following error using the class property:

Code:
could not resolve property: class of: net.persofin.transactions.ScheduledThirdTransaction



[EDIT] Well i guees this answer should help me: http://forum.hibernate.org/viewtopic.php?p=2381968 , I ll try and keep you touched[/EDIT]


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 07, 2008 1:46 pm 
Newbie

Joined: Wed Aug 06, 2008 4:00 pm
Posts: 4
Well, i modified my mapping according to the post but it still doesn't work. I can't include a subclass tag inside another subclass tag:
Code:
<hibernate-mapping>

    <class name="net.persofin.transactions.Transaction" lazy="false" table="TRANS">
   
        <id name="id" column="TRS_ID">
            <generator class="increment"/>
        </id>       
        <discriminator column="KIND" type="string"/>   
        <property name="memo" column="MEMO"/>
        <property name="executionDate" column="EXEDATE" />
        <property name="amount" column="AMOUNT" />
        <property name="type" column="TYPE" />
        <property name="assetFactor" column="ASSET_FACTOR" />       
        <many-to-one name="account" class="net.persofin.accounts.Account" column="ACC_ID"/> 
        <subclass name="net.persofin.transactions.TransferTransaction" lazy="false"   discriminator-value="TRANSFER" >
                   <join table="TRANSFER">
                     <key column="TRANS_ID"/>
                      <many-to-one name="linkedTrans"   column="TRANS_TRANS_ID"/>
                     <many-to-one name="accountFrom"   column="TRANS_ACC_ID"/>
                  </join>       
        </subclass>
        <subclass name="net.persofin.transactions.ThirdTransaction" lazy="false"  discriminator-value="THIRD">
                <join table="THIRDTRANS">
                 <key column="THIRDTR_ID"/>
                      <many-to-one name="third"  column="TIR_ID"/> 
                      <many-to-one name="cat"  column="CAT_ID"/>                   
                </join>   
                [b]<subclass name="net.persofin.transactions.ScheduledThirdTransaction" lazy="false" discriminator-value="SCHD_THIRD">
                          <join table="SCHD_THIRDTRANS">
                               <key column="SCHDTR_ID"/>
                               <property name="NEXT_EXE_DATE"/>
                               <property name="FREQUENCY"/>
                               <property name="SCALE"/>
                               <property name="ACTIVE"/>
                         </join>               
                </subclass>    [/b]
        </subclass>
        <subclass name="net.persofin.transactions.StockTransaction" lazy="false" discriminator-value="STOCK">
           <join table="STOCKTRANS">
               <key column="STOCKTR_ID"/>
                <many-to-one name="stock"  column="STK_ID"/> 
                <property name="commissions"  column="COMMISSIONS"/>
                <property name="unitPrice"  column="UNIT_PRICE"/>
                <property name="qty"  column="QTY"/>   
            </join>                       
        </subclass>       
    </class>

</hibernate-mapping>


How can I do that? Thanks again[/code]


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.