Java / JPA | query using the specified inheritance type
•
Java
I am building a query on a generic table "sample", and I have several types inherited from this table "sampleone", "sampletwo"
select s from Sample where s.type = :type
Where type will be the identifier value of the table Is it possible in any way (and avoid creating an entity specific query for each sampleone, sampletwo... Etc.)
I am very grateful for any comments on this topic,
Cordial greetings, P
Solution
In JPA 2.0, you can use type expression (although it is not applicable to parameters in Hibernate at present, see hhh-5282):
select s from Sample s where TYPE(s) = :type
A similar hibernate specific expression is class:
select s from Sample s where s.class = :type
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码