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
}
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.