Can someone please give me an example of a JPA query which select few selected sub-classed entities? For example, the parent entity is Institution. I have sub-classed it to Manufacturers, Suppliers, Service Providers. I want to get all the Suppliers and Service Providers, but not Manufacturers in a single query which return Institution objects.
I googled, but could not locate any resource addressing this specific issue. Thanks in advance.
from the JPA 2.0 Spec:
4.6.17.4 Entity Type Expressions [...] The Java class of the entity is used as an input parameter to specify the entity type. Examples:
SELECT e FROM Employee e WHERE TYPE(e) IN (Exempt, Contractor)
SELECT e FROM Employee e WHERE TYPE(e) IN (:empType1, :empType2)
[...]
so I'd try something like:
List<Institution> institutions = em.createQuery("SELECT i FROM Institution i WHERE TYPE(i) IN ( Supplier, ServiceProvider ) ).getResultList();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With