org.hibernate.hql.internal.ast.QuerySyntaxException:路径无效:

时间:2018-03-03 23:03:42

标签: spring spring-boot

升级到Spring Boot 2.0后,我的工作SQL会抛出以下异常 - 请帮帮我。

  

引起:java.lang.IllegalArgumentException:   org.hibernate.hql.internal.ast.QuerySyntaxException:路径无效:   '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(原生方法)   〜[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常见   帧省略引起的:   org.hibernate.hql.internal.ast.QuerySyntaxException:路径无效:   '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。(HQLQueryPlan.java:115)   〜[hibernate-core-5.2.14.Final.jar:5.2.14.Final] at   org.hibernate.engine.query.spi.HQLQueryPlan。(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个常见帧   省略

1 个答案:

答案 0 :(得分:0)

我相信这是Hibernate 5.2中的一个小错误。我也碰到了它。经过一番调查后,我发现它是由以大写字母开头的枚举名称引起的。

只需将您的枚举重命名为ListingStatus并且它应该有效(无论如何,LISTINGSTATUS不是标准的Java命名约定)。

此处报告了错误:https://hibernate.atlassian.net/browse/HHH-12429

更新

我要求关闭此问题,因为它的目的是行为,如下所述:https://vladmihalcea.com/the-performance-penalty-of-class-forname-when-parsing-jpql-and-criteria-queries

如果要返回旧行为,请将属性设置为:hibernate.query.conventional_java_constants为false