-->
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.  [ 3 posts ] 
Author Message
 Post subject: How many select?
PostPosted: Tue Nov 28, 2006 4:01 am 
Newbie

Joined: Tue Nov 28, 2006 3:52 am
Posts: 5
I'm using Hibernate 3.1.3

This is a simple class model

public abstract Cat {
private String name;
private int age;
public abstract boolean processAge();
// setter and getter methods
........
}

public BigCat{
public boolean processAge(){
...........
}
}

public LittleCat{
public boolean processAge(){
...........
}
}

(In real enviroment I have about ten subclass)

and a mapping like:

<hibernate-mapping>
<class name="Cat" table="CATS">
<id name="catId" type="long" column="CAT_ID">
<generator class="native"/>
</id>
<discriminator column="internalDiscriminator" type="string"/>
<property name="name"/>
<property name="age"/>

<subclass name="BigCat"/>
<subclass name="LittleCat"/>

</class>
</hibernate-mapping>



It works, but if I try a java statement
List result = getSession().createQuery("BigCat").list();
Hibernate process two select from the table CATS, one for each subclass with internalDiscriminator='BigCat' and internalDiscriminator='LittleCat'.

I find this inefficient and unjustified, how can I perform only one select?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 28, 2006 4:07 am 
Regular
Regular

Joined: Tue May 16, 2006 3:32 am
Posts: 117
Add polymorphism="explicit" in your mapping file for class element. Read about polymorphic queries in Hibernate reference doc.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 28, 2006 4:16 am 
Newbie

Joined: Tue Nov 28, 2006 3:52 am
Posts: 5
Thanks, JayeshJ

I voted your replay


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.