Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use type of object in HQL where clause

In my domain model I have an abstract class CommunicationChannelSpecification, which has child classes like FTPChannelSpecification, EMailChannelSpecification and WebserviceChannelSpecification. Now I want to create an HQL query which contains a where clause that narrows down the result to certain types of channel specifications. E.g. (in plain English) select all CommunicationChannelSpecifications that whose types occur in the set {FTPChannelSpecification, WebserviceChannelSpecification}.

How can this be achieved in HQL? I'm using NHibernate 2.0.1 and a table per subclass inheritance mapping strategy...

Thanks!

Pascal

like image 377
Pascal Lindelauf Avatar asked Mar 01 '23 03:03

Pascal Lindelauf


1 Answers

Not positive in NHibernate, but in Hibernate, there are two special properties that are always referenced id and class. So, for your particular case, I'd do

from CommunicationChannelSpecifications spec where spec.class in (?)
like image 115
bangroot Avatar answered Mar 06 '23 15:03

bangroot