Reputation: 1
After upgrading to Spring Boot 2.0 my working SQLs are throwing following exception - Please help me here.
Caused by: java.lang.IllegalArgumentException:
org.hibernate.hql.internal.ast.QuerySyntaxException: Invalid path:
'com.wtp.core.constant.RECORDSTATUS.ACTIVE' [SELECT l FROM
com.wtp.core.entity.ListingComments l WHERE l.listingID = :listingID
AND l.recordStatus=com.wtp.core.constant.RECORDSTATUS.ACTIVE AND
l.listingStatus =com.wtp.core.constant.LISTINGSTATUS.ACTIVE ORDER BY
l.createdOn asc] at
org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:133)
~[hibernate-core-5.2.14.Final.jar:5.2.14.Final] at
org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:157)
~[hibernate-core-5.2.14.Final.jar:5.2.14.Final] at
org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:164)
~[hibernate-core-5.2.14.Final.jar:5.2.14.Final] at
org.hibernate.internal.AbstractSharedSessionContract.createQuery(AbstractSharedSessionContract.java:670)
~[hibernate-core-5.2.14.Final.jar:5.2.14.Final] at
org.hibernate.internal.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:23)
~[hibernate-core-5.2.14.Final.jar:5.2.14.Final] at
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
~[na:1.8.0_131] at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
~[na:1.8.0_131] at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
~[na:1.8.0_131] at java.lang.reflect.Method.invoke(Method.java:498)
~[na:1.8.0_131] at
org.springframework.orm.jpa.ExtendedEntityManagerCreator$ExtendedEntityManagerInvocationHandler.invoke(ExtendedEntityManagerCreator.java:350)
~[spring-orm-5.0.4.RELEASE.jar:5.0.4.RELEASE] at
com.sun.proxy.$Proxy120.createQuery(Unknown Source) ~[na:na] at
org.springframework.data.jpa.repository.query.SimpleJpaQuery.validateQuery(SimpleJpaQuery.java:87)
~[spring-data-jpa-2.0.5.RELEASE.jar:2.0.5.RELEASE] ... 76 common
frames omitted Caused by:
org.hibernate.hql.internal.ast.QuerySyntaxException: Invalid path:
'com.wtp.core.constant.RECORDSTATUS.ACTIVE' [SELECT l FROM
com.wtp.core.entity.ListingComments l WHERE l.listingID = :listingID
AND l.recordStatus=com.wtp.core.constant.RECORDSTATUS.ACTIVE AND
l.listingStatus =com.wtp.core.constant.LISTINGSTATUS.ACTIVE ORDER BY
l.createdOn asc] at
org.hibernate.hql.internal.ast.QuerySyntaxException.convert(QuerySyntaxException.java:74)
~[hibernate-core-5.2.14.Final.jar:5.2.14.Final] at
org.hibernate.hql.internal.ast.ErrorCounter.throwQueryException(ErrorCounter.java:91)
~[hibernate-core-5.2.14.Final.jar:5.2.14.Final] at
org.hibernate.hql.internal.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:272)
~[hibernate-core-5.2.14.Final.jar:5.2.14.Final] at
org.hibernate.hql.internal.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:189)
~[hibernate-core-5.2.14.Final.jar:5.2.14.Final] at
org.hibernate.hql.internal.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:141)
~[hibernate-core-5.2.14.Final.jar:5.2.14.Final] at
org.hibernate.engine.query.spi.HQLQueryPlan.<init>(HQLQueryPlan.java:115)
~[hibernate-core-5.2.14.Final.jar:5.2.14.Final] at
org.hibernate.engine.query.spi.HQLQueryPlan.<init>(HQLQueryPlan.java:77)
~[hibernate-core-5.2.14.Final.jar:5.2.14.Final] at
org.hibernate.engine.query.spi.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:153)
~[hibernate-core-5.2.14.Final.jar:5.2.14.Final] at
org.hibernate.internal.AbstractSharedSessionContract.getQueryPlan(AbstractSharedSessionContract.java:553)
~[hibernate-core-5.2.14.Final.jar:5.2.14.Final] at
org.hibernate.internal.AbstractSharedSessionContract.createQuery(AbstractSharedSessionContract.java:662)
~[hibernate-core-5.2.14.Final.jar:5.2.14.Final] ... 84 common frames
omitted
Upvotes: 0
Views: 2977
Reputation: 301
I believe this is a minor bug in Hibernate 5.2. I ran into it as well. After some investigation I worked out it is caused by the name of the enum starting with capitals.
Just rename your enum to ListingStatus and it should work (LISTINGSTATUS is not standard java naming convention anyway).
Bug is reported here: https://hibernate.atlassian.net/browse/HHH-12429
Update:
I asked for this issue to be closed since it is intended behaviour as explained here: https://vladmihalcea.com/the-performance-penalty-of-class-forname-when-parsing-jpql-and-criteria-queries
If you want to go back to the old behaviour set the property: hibernate.query.conventional_java_constants
to false
Upvotes: 1