bstick12
bstick12

Reputation: 1749

Querying Hibernate based on super type

I have a class similar to the one below persisting to the database using Hibernate. Is there any way to query Hibernate on the objectType based on the super class of the objectType.

e.g. If you persisted two objects, one with Integer.class and another with Float.class as the objectType can I write a query that will return both objects if I ask for objectType = Number.class

@Entity
public class ToPersist
{
    public String name
    public Class<?> objectType
}

Upvotes: 0

Views: 170

Answers (1)

JB Nizet
JB Nizet

Reputation: 692281

No. A HQL/JPQL query is always transformed into a SQL query, and the database doesn't know about the inheritance relationships between Java classes.

Upvotes: 1

Related Questions