1

I want to check discriminator type in jpa named query like any other attribute.

How can I check?

Naveen Kocherla
  • 399
  • 9
  • 27

2 Answers2

1

Use TYPE in JPA 2.0: "select p from Employee e join e.projects p where type(p) = LargeProject"

Chris
  • 20,138
  • 2
  • 29
  • 43
1

You could use the Criteria API: https://wiki.eclipse.org/EclipseLink/UserGuide/JPA/Basic_JPA_Development/Querying/Criteria
But this would be quiet overkill.

Use the JPA TYPE() so a Query could look like this:

SELECT s FROM Superclass s WHERE TYPE(s) = Superclass

This will compare the value set as DiscriminatorValue, so it acts like instanceof.

see also https://stackoverflow.com/a/7808003/5267377

Community
  • 1
  • 1
ToxicWaste
  • 135
  • 1
  • 7