-->
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: Querying from Inheritance Hierarchy
PostPosted: Tue Apr 06, 2010 1:57 pm 
Newbie

Joined: Tue Apr 06, 2010 1:51 pm
Posts: 1
Location: India
Hi,

Suppose I have inheritance hierarchy SuperClass is Payment, Subclass is CreditPayment,CashPayment.

And I query from hql "from Payment p". It will fetch the records from Payment, CreditPayment and CashPayment. But I want records from only Payments and not from it's subclasses. How to do that. I tried explicit polymorphism. But not working.

Suppose Payment has 1 record, CreditPayment has 2 records and CashPayment has 3 records with following inheritance hierarchy.
If I select using HQL " from Payment P ", I will get 6 records. But I do not want hibernate to use implicit polymorphism, I want hibernate to select from only Payment and not from CashPayment and CreditPayment. How do I do it. I tried Poymorphism="explicit" But I still get 6 records. Please help.


Code:
<?xml version="1.0"?> 
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" 
    "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"> 
<hibernate-mapping package="com.test"> 
    <class name="Payment" table="payment" polymorphism="explicit"> 
        <id column="id" type="long" name="id"> 
            <generator class="native" /> 
        </id> 
        <discriminator column="payType" type="string"></discriminator> 
        <property name="amount" column="amount" type="double" /> 
 
        <subclass name="CashPayment" discriminator-value="cash" > 
            <property name="testProperty" type="string" 
                column="testProperty" /> 
        </subclass> 
        <subclass name="CreditPayment" discriminator-value="credit"> 
            <property name="testProperty2" type="string" 
                column="testProperty2" /> 
        </subclass> 
 
    </class> 
</hibernate-mapping>


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.