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

Criteria query generates invalid query resulting in QuerySyntaxException

Description

I have a complicated Criteria query involving a bunch of sub-selects, etc.

Buried in there is a simple test for a boolean value constructed like this:

1 builder.isTrue(foobar.get(Foobar_.primary));

Attempting to perform the query results in the following exception:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 org.hibernate.hql.internal.ast.QuerySyntaxException: unexpected AST node: = near line 1, column 2191 [select distinct generatedAlias0.id ... and ( generatedAlias8.primary = true=true ) ... at org.hibernate.jpa.spi.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1679) at org.hibernate.jpa.spi.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1602) at org.hibernate.jpa.spi.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1608) at org.hibernate.jpa.spi.AbstractEntityManagerImpl.createQuery(AbstractEntityManagerImpl.java:551) at org.hibernate.jpa.criteria.CriteriaQueryImpl$1.buildCompiledQuery(CriteriaQueryImpl.java:316) at org.hibernate.jpa.criteria.compile.CriteriaCompiler.compile(CriteriaCompiler.java:130) at org.hibernate.jpa.spi.AbstractEntityManagerImpl.createQuery(AbstractEntityManagerImpl.java:699) at sun.reflect.GeneratedMethodAccessor322.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.springframework.orm.jpa.SharedEntityManagerCreator$SharedEntityManagerInvocationHandler.invoke(SharedEntityManagerCreator.java:298) at com.sun.proxy.$Proxy64.createQuery(Unknown Source) ... 24 more

Note the generated query contains generatedAlias8.primary = true=true.

I tried a few variants, like builder.equal(builder.literal(true), foobar.get(Foobar_.primary)) and builder.isFalse(builder.not(foobar.get(Foobar_.primary))) but those didn't fix it.

Changing the Java property name from primary to primaree doesn't help either (thought it might be a special keyword (the MySQL column name had already been changed long ago to isprimary)).

This problem originally occurred in 5.0.7, after which I tried upgrading to 5.1.8. I have not tried 5.2.x because it's incompatible with Spring 4.3.x's HibernateJpaDialect due to the change in return type of Session.getFlushMode() and so my app won't build.

Environment

Hibernate 5.1.8 using JPA, MySQL

Status

Assignee

Unassigned

Reporter

Archie Cobbs

Fix versions

None

Labels

None

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Affects versions

5.1.8

Priority

Major