jpa join query on a subclass
- by Brian
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.