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

Select alias in Criteria API seems to bleed into where condition

Description

1 2 3 4 5 6 7 CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<Object> criteriaQuery = cb.createQuery(); Root<User> root = criteriaQuery.from(User.class); criteriaQuery.where(cb.equal(root.get("id"), cb.parameter(Integer.class, "id"))); criteriaQuery.select(root.get("id").alias("x")); em.createQuery(criteriaQuery);

Fails with the following exception:

1 2 3 4 5 6 7 8 9 10 11 org.hibernate.hql.internal.ast.QuerySyntaxException: unexpected token: as near line 1, column 169 [select generatedAlias0.id as x from org.springframework.data.jpa.repository.projections.ProjectionJoinIntegrationTests$User as generatedAlias0 where generatedAlias0.id as x=:id] at org.hibernate.hql.internal.ast.QuerySyntaxException.convert(QuerySyntaxException.java:74) at org.hibernate.hql.internal.ast.ErrorTracker.throwQueryException(ErrorTracker.java:93) at org.hibernate.hql.internal.ast.QueryTranslatorImpl.parse(QueryTranslatorImpl.java:297) at org.hibernate.hql.internal.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:189) at org.hibernate.hql.internal.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:144) at org.hibernate.engine.query.spi.HQLQueryPlan.<init>(HQLQueryPlan.java:118) at org.hibernate.engine.query.spi.HQLQueryPlan.<init>(HQLQueryPlan.java:78) at org.hibernate.engine.query.spi.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:158) at org.hibernate.internal.AbstractSharedSessionContract.getQueryPlan(AbstractSharedSessionContract.java:595) at org.hibernate.internal.AbstractSharedSessionContract.createQuery(AbstractSharedSessionContract.java:704)

Note the where clause mentioned in the exception: where generatedAlias0.id as x=:id.

This happens only in 5.4.1-SNAPSHOT; 5.4.0.Final seems to be fine.

Environment

None

Status

Assignee

Guillaume Smet

Reporter

Jens Schauder

Fix versions

Labels

None

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Worked in

5.4.0

Components

Affects versions

5.4.1

Priority

Major