-->
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.  [ 4 posts ] 
Author Message
 Post subject: HQL - instanceof operator
PostPosted: Tue Oct 20, 2009 7:42 am 
Beginner
Beginner

Joined: Wed Jun 28, 2006 2:24 pm
Posts: 30
Location: Brazil
In the following issue, Gavin King says that can use foo.class in (...) as an instanceof operator. How? Any example?

http://opensource.atlassian.com/project ... se/HB-1470

Thanks


Top
 Profile  
 
 Post subject: Re: HQL - instanceof operator
PostPosted: Thu Nov 05, 2009 2:26 am 
Newbie

Joined: Mon Mar 31, 2008 6:14 am
Posts: 2
I went looking for this myself and had a guess at the syntax - for anyone else looking this worked for me as an example:

superclass.class in(SubClass)

So for a very basic example:

from Wheel wheel
left outer join wheel.car
where car.class in(Subaru)

this would find all wheels for Subarus. This is taken from a much more complicated query that i've tried to extract the important parts from but I think that would work. It gives an idea of the syntax at least.


Top
 Profile  
 
 Post subject: Re: HQL - instanceof operator
PostPosted: Thu Jul 22, 2010 6:44 pm 
Newbie

Joined: Wed Oct 19, 2005 10:47 am
Posts: 4
"The special property class accesses the discriminator value of an instance in the case of polymorphic persistence. A Java class name embedded in the where clause will be translated to its discriminator value." - from JBoss documentation

The following HQL will return only superclass instances. You can probably also use "not in(MySubClass1 , MySubClass2)", but I haven't tried that.

"select model from MySuperclass model where model.class != MySubClass1 and model.class != MySubClass2"


Top
 Profile  
 
 Post subject: Re: HQL - instanceof operator
PostPosted: Fri Jul 23, 2010 9:52 am 
Newbie

Joined: Wed Oct 19, 2005 10:47 am
Posts: 4
I have confirmed that the following HQL will return only instances of the superclass:

"select model from MySuperclass model where model.class not in(MySubClass1, MySubClass2, MySubClass3)"


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.