Jpa join request in subclass

I have the following relationships in JPA (hibernation).

Object X has two subclasses: Y and Z.

Object A has manyToOne related to object X. (Note that this is a one-way relationship, so object X cannot see object A).

Now I want to get the maximum value of the column in object A, but only where the relation has a certain subtype, that is ... Y.

So this is equivalent ... to get the maximum value of column1 in object A, in all instances of A, where they relate to Y. Is this possible? I lost a little how to request it.

I was thinking of something like:

String query = "SELECT MAX(a.columnName) FROM A a join a.x;
Query query = super.entityManager.createQuery(query);
query.execute();

However, this does not account for subclass X ... so I lost a bit.

Any help would be greatly appreciated.

+5
2

, - :

SELECT MAX (a.columnName) FROM A a join a.x WHERE a.x.class= y.class

, ,

0

JPA 2.0 , TYPE. JPA 2.0:

4.6.17.4

. TYPE .

:

entity_type_expression ::=
         type_discriminator |
         entity_type_literal |
         input_parameter
type_discriminator ::=
         TYPE(identification_variable |
                single_valued_object_path_expression |
                input_parameter )

entity_type_literal .

Java .

:

SELECT e
FROM Employee e
WHERE TYPE(e) IN (Exempt, Contractor)

SELECT e
FROM Employee e
WHERE TYPE(e) IN (:empType1, :empType2)

SELECT e
FROM Employee e
WHERE TYPE(e) IN :empTypes

SELECT TYPE(e)
FROM Employee e
WHERE TYPE(e) <> Exempt

JPA 1.0 , , JPA 1.0, JPQL.

HQL, class:

, class . Java, where, .

from Cat cat where cat.class = DomesticCat

, - :

SELECT MAX(a.columnName) FROM A a where a.x.class = Y
+14

All Articles