We're updating the issue view to help you get more done. 

Criteria API multiselect aliases are not passed through to the JPQL query and they are not available in ResultTransformer

Description

Assuming we have a DTO like this one:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 public class PostCommentSummary { private Number id; private String title; private String review; public PostCommentSummary( Number id, String title, String review) { this.id = id; this.title = title; this.review = review; } public PostCommentSummary() {} public Number getId() { return id; } public String getTitle() { return title; } public String getReview() { return review; } }

and we want to write the following Criteria API query:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 CriteriaBuilder builder = entityManager.getCriteriaBuilder(); CriteriaQuery<Object[]> criteria = builder.createQuery(Object[].class); Root<PostComment> root = criteria.from(PostComment.class); Join<PostComment, Post> postJoin = root.join("post"); criteria.multiselect( root.get(PostComment_.id).alias("id"), root.get(PostComment_.review).alias("review"), postJoin.get(Post_.title).alias("title") ); criteria.where(builder.like(postJoin.get(Post_.title), "high-performance%")); List<PostCommentSummary> comments = entityManager .createQuery(criteria) .unwrap(Query.class) .setResultTransformer(Transformers.aliasToBean(PostCommentSummary.class)) .getResultList();

The aliases are not passed through and the DTO will contain only null values.

Environment

None

Status

Assignee

Unassigned

Reporter

Vlad Mihalcea

Fix versions

Labels

None

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Components

Priority

Major