I have a simple hierarchy TradeCustomer
is an OrganisationRole
. An OrganisationRole
is linked to Organisation
s. Organisation
has a property roles
containing all roles of an organisation.
I'd like to write a JPA query using the CriteriaBuilder
which root is Organisation
but access a property of TradeCustomer
, eg, I need to join Organisation
with OrganisationRole
and cast it to TradeCustomer
.
Here is my solution:
CriteriaQuery<String> query = cb.createQuery(String.class);
Root<Organisation> root = query.from(Organisation.class);
Join<Organisation, TradeCustomer> tcJoin = root.join("roles");
query.select(tcJoin.get(TradeCustomer_.rate));
The important bit is to use the name of the column ( roles
) instead of Organisation_.roles.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.