-->
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 (kind of)
PostPosted: Tue Jun 02, 2009 3:34 pm 
Newbie

Joined: Wed Jul 30, 2008 5:50 am
Posts: 15
I have a Single table per class hierarchy mapping (single table).

I have an abstract base with two subclasses.

Basically I want to execute a polymorphic query - meaning I want a query that returns a list of the base class.

Problem is that I have a different "where clauses" for every subclass and the where clauses are based on properties unique for the subclass (do not exist in the base class).

Seems like a union is required. So HQL is not really an option. I tried using something like

select {gv.*}, gv.Product_id from zad_videos gv where gv.widget_id = :wid " +
union all
select {pv.*}, pv.title, pv.user_id, pv.widget_id from zad_videos pv join zad_catalog_products cp on pv.product_id = cp.product_id where cp.catalog_id = :catid

and .addEntity("gv", superclass1) + .addEntity("pv", superclass2)

the problem is that each sql in the union generates the fields based on the entity it is mapped to with the addentity so the SQLs do not match as should be in the UNION.

The problem with HQL is that I will have something like

"select b from BaseClass b .....where... "

and then I need to access (in the where) b.property which is based on the actual type - a property that does not exist in the base class - Is there a way to handle this properly?

Thanks,
Arie


Top
 Profile  
 
 Post subject: Re: Polymorphism (kind of)
PostPosted: Wed Jun 03, 2009 1:35 am 
Newbie

Joined: Wed Jul 30, 2008 5:50 am
Posts: 15
I would say that a possible solution for example will be casting within the HQL. From my impressions and searches it seems is it not supported....

true?


Top
 Profile  
 
 Post subject: Re: Polymorphism (kind of)
PostPosted: Wed Jun 03, 2009 4:47 am 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
Male and Female both extend Person

Select person from Person person, Male male
where male.specificProp = :param
and person = male

easy to read ;)

Anthony

_________________
Anthony,
Get value thanks to your skills: http://www.redhat.com/certification


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.