-->
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.  [ 5 posts ] 
Author Message
 Post subject: Can I check real type of object in HQL Where clause?
PostPosted: Wed Aug 31, 2005 10:22 am 
Need something like:
"WHERE Person Is Manager"

or even

"WHERE IF Person Is Manager THEN (Person as Manager).Salary > 1000 ELSE 1=1 END"

Does HQL allow that?


Top
  
 
 Post subject:
PostPosted: Wed Aug 31, 2005 12:09 pm 
Contributor
Contributor

Joined: Thu May 12, 2005 9:45 am
Posts: 593
Location: nhibernate.org
Try
Code:
from Manager Person where Person.Salary > 1000

_________________
Pierre Henri Kuaté.
Get NHibernate in Action Now!


Top
 Profile  
 
 Post subject: 2KPixel
PostPosted: Wed Aug 31, 2005 12:48 pm 
Thank you!

The problem is that I have two classes
Person and Manager. Person is the base class.

I need select all objects of class Person.
If the object is actually of class Manager I
wont additionaly check in the query that it's Salary is less then 1000
("Salary" is property of class Manager)


Top
  
 
 Post subject:
PostPosted: Wed Aug 31, 2005 3:44 pm 
Regular
Regular

Joined: Tue May 24, 2005 12:55 pm
Posts: 56
Please post the maps for these 2 classes. HQL relies on the mapping. Assuming you are subclassing these in your mapping you will have to put the property that holds your discriminator-value in the WHERE clause. (where obj.property = discrminator_value_wanted


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 02, 2005 6:34 am 
Contributor
Contributor

Joined: Thu May 12, 2005 9:45 am
Posts: 593
Location: nhibernate.org
AFAIK, you will have to issue two queries:
Code:
from Manager m where m.Salary > 1000

and
Code:
from Person p where p.Discrimitator <> ManagerDisc


(replace p.Discrimitator by the name of your discriminator and ManagerDisc by the discriminator value of the class Manager)

_________________
Pierre Henri Kuaté.
Get NHibernate in Action Now!


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