How to perform a non-polymorphic HQL query in Hibernate?
Posted
by Eli Acherkan
on Stack Overflow
See other posts from Stack Overflow
or by Eli Acherkan
Published on 2010-01-19T11:20:57Z
Indexed on
2010/04/01
9:43 UTC
Read the original article
Hit count: 272
Hi all,
I'm using Hibernate 3.1.1, and in particular, I'm using HQL queries.
According to the documentation, Hibernate's queries are polymorphic:
A query like:
from Cat as cat
returns instances not only ofCat
, but also of subclasses likeDomesticCat
.
How can I query for instances of Cat, but not of any of its subclasses?
I'd like to be able to do it without having to explicitly mention each subclass.
I'm aware of the following options, and don't find them satisfactory:
- Manually filtering the instances after the query, OR:
- Manually adding a WHERE clause on the discriminator column.
It would make sense for Hibernate to allow the user to decide whether a query should be polymorphic or not, but I can't find such an option.
Thanks in advance!
© Stack Overflow or respective owner