jpa join query on a subclass
Posted
by Brian
on Stack Overflow
See other posts from Stack Overflow
or by Brian
Published on 2010-06-02T11:38:21Z
Indexed on
2010/06/02
16:03 UTC
Read the original article
Hit count: 213
I have the following relationships in JPA (hibernate).
Object X has two subclasses, Y and Z.
Object A has a manyToOne relationship to object X. (Note, this is a one-sided relationship so object X cannot see object A).
Now, I want to get the max value of a column in object A, but only where the relationship is of a specific subtype, ie...Y.
So, that equates to...get the max value of column1 in object A, across all instances of A where they have a relationship with Y. Is this possible? I'm a bit lost as how to query 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 that doesn't take account of the subclass of X...so I'm a bit lost.
Any help would be much appreciated.
© Stack Overflow or respective owner