1

我有 2 个这样的实体:

EntityX:
id Long
name  String
entityYId  Long


EntityY (this entity is very hard, because it has a lot of data)
id Long
name String
xxx
xxx
.....

我需要做类似的事情

Root<EntityX> xRoot = criteriaQuery.from(EntityX.class);
Join<EntityX, EntityY> yJoin = xRoot.join("entityYId", JoinType.LEFT);    

我需要 yJoin 因为我需要 JPA 标准这个多选:

pId = xRoot.get("id");   
pName = xRoot.get("name");
pEntityYName = yJoin.get("name");

cr.multiselect(
    cb.construct(
      ResultData.class,
      pId,
      pName,
      pEntityYName));

我可以做吗?如果不可能,我能做些什么来解决这个问题,记住!我只需要 EntityX 中的“entityYId”而不是所有 entityY 元素。

谢谢!

4

1 回答 1

1

您可以在 Root 类上使用 select 方法。有关更多信息,请参见http://www.objectdb.com/java/jpa/query/jpql/select#SELECT_in_Criteria_Queries_

于 2012-02-23T15:48:32.240 回答