-->
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: polymorphic query in HQL using unmapped interface?
PostPosted: Wed May 11, 2005 2:07 am 
Regular
Regular

Joined: Fri Oct 01, 2004 2:19 am
Posts: 111
Location: Melbourne, Australia
Hibernate version: 3.0rc1

I read in the documentation (sections 9.1.6/9.1.7) that, using implicit
polymorphism it is possible to query using some base interface and
essentially get all classes which implement the interface and match
the query.

Well, I'm trying to use HQL to perform this (see code snippet below):
Code:
... java classes ...
public inteface BaseI {}

public class BaseClass { int prop1;}
public class Class1 extends BaseClass implements BaseI { int prop2;}
public class Class2 extends BaseClass  { string propS;}


The hibernate mapping includes mappings for the actual classes BaseClass, Class1 and Class2. Next comes the query definition and
it goes something like this:
Code:
<query name="someQ">
<![CDATA[
        select  b
        from    BaseI as b
        where b.class like ':className'
        and b. prop1 = 10 ]]>
</query>


The intent is to get those objects implementing BaseI without regard to
the actual class (in this case instances of Class1), which I thought
was what the document was referring to.

However, I get an error when starting up the application, which states that BaseI
is not mapped, which is correct, but I thought that it would not need to be
mapped as a persistent class, rather that the mapping information will
capture this and will allow Hibernate to convert the query to whatever
multiple SQL queries are required to obtain the objects.

Anybody knows whether this is possible, or am I completely misreading the
document and I need to reorganise the mapping document/class hierarchy?

_________________
Cheers,

Bonny

please don't forget to rate :)


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.