Reputation: 153
I have 2 entities like these:
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
.....
I need to do something like
Root<EntityX> xRoot = criteriaQuery.from(EntityX.class);
Join<EntityX, EntityY> yJoin = xRoot.join("entityYId", JoinType.LEFT);
I need yJoin because I need with JPA criteria this multiselect:
pId = xRoot.get("id");
pName = xRoot.get("name");
pEntityYName = yJoin.get("name");
cr.multiselect(
cb.construct(
ResultData.class,
pId,
pName,
pEntityYName));
Can I do it? If it not possible, what can I do to solve this, REMEMBER! I need only "entityYId" in EntityX not all entityY element.
Thanks!
Upvotes: 1
Views: 7474
Reputation: 2395
You can use the select method on Root class. See http://www.objectdb.com/java/jpa/query/jpql/select#SELECT_in_Criteria_Queries_ for more info
Upvotes: 1