-->
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: polymorphism, mapping and HQL
PostPosted: Wed Aug 24, 2005 7:15 pm 
Newbie

Joined: Tue May 31, 2005 8:19 pm
Posts: 16
Location: San Francisco, CA
Hibernate version: 3.0.5

I would like to have "mapped" polymorphism AND explicit polymorphism, but after much research, can not figure out how to do this, or if it is possible.

I want "mapped" polymorphism for polymorphic associations, for updates.

I do not want implicit polymorphism for polymorphic queries, because I have a superclass and 70+ immediate subclasses, so polymorphic queries would not be practical. I will only need to query for superclass instances, OR a specific subclass instance.

For example, using table per subclass:
superclass:
public class SuperClass {
private Long id;
private String name;
//constructor,getters/setters
}
<hibernate-mapping>
<class name="SuperClass" table="SuperClass" polymorphism="explicit">
<id name="id" type="long">
<column name="id" not-null="true"/>
<generator class="identity"/>
</id>
<property name="name" type="string"/>
</class>
</hibernate-mapping>

example of one of 70+ subclasses:
public class SubClass extends SuperClass {
private Long id;
private Integer value;
// constructor, getters,setters
}
<hibernate-mapping>
<joined-subclass name="SubClass" table="SubClass" extends="SuperClass">
<key column="id"/>
<property name="value" type="integer"
</joined-subclass>
</hibernate-mapping>


If i use this HQL query, Hibernate will join SuperClass to all <joined-subclass> subclasses, which is not practical given the number of subclasses.
<query name="SomeQuery">
from SuperClass sc
where sc.name = :name
</query>

Is there a way to use HQL to query on just the SuperClass without joins to all subclasses ? Or any design suggestions ?


Top
 Profile  
 
 Post subject: Re: polymorphism, mapping and HQL
PostPosted: Thu Aug 25, 2005 12:23 am 
Expert
Expert

Joined: Mon Feb 14, 2005 12:32 pm
Posts: 609
Location: Atlanta, GA - USA
Have you tried what you're talking about using just polymorphism="implicit" ?

I'm pretty sure that if you select on the SuperClass, you'll get all of them, and if you select on any of the subclasses, you'll get only the subclass(es)

When updating, polymorphism shouldn't be an issue.

_________________
Preston

Please don't forget to give credit if/when you get helpful information.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 25, 2005 1:06 pm 
Newbie

Joined: Tue May 31, 2005 8:19 pm
Posts: 16
Location: San Francisco, CA
Thanks. Yes, I first tried implicit and that resulted in the problem, so I changed to explicit polymorphism to try to solve it.

I found another post which addresses my problem. What I am trying to do is not consistent with OO approach.

http://forum.hibernate.org/viewtopic.ph ... lymorphism

For my purposes, I was able to get around the problem by just selected the individual properities I needed (a report query), e.g.

<query name="SomeQuery">
select sc.id, sc.name
from SuperClass sc
where sc.name = :name
</query>

With this query, Hibernate does not join to the subclass tables, and given that I have 70 subclasses, this is the behavior I want.

Thanks for suggestion.


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.