我有以下实体结构:
+-----------+ +-------------+
| User | -------------> | Role |
+-----------+ +-------------+
^
|
+-------+---------+
| |
+-----------+ +-----------+ +------------+
| Role1 | | Role2 |--------> | SomeEntity |
+-----------+ +-----------+ +------------+
我想获取其 Role2 具有 SomeEntity 具有特定属性值的所有用户的名称。我需要使用 JPA 标准 API 来执行此操作。
到目前为止我所做的是:
CriteriaBuilder cb = ...
CriteriaQuery<String> query = cb.createQuery(String.class);
Root<User> user = query.from(User.class);
SetJoin<User, Role> userRolesJoin = user.join(User_.roles);
// As you can see the userRolesJoin is of type Role and a Role doesn't have
// an property someEntity. So how to "cast" the userRolesJoin into an
// SetJoin<User, Role2>.
如何在这里进行多态查询?有什么建议么?
不幸的是,JPA 标准 API 不如 Hibernate 的标准 API 直观。