当前位置: 首页 > 面试题库 >

@OrderBy导致org.hibernate.HibernateException:无法解析按片段

祝高阳
2023-03-14
问题内容

我在项目上添加了@OrderBy,现在出现以下错误:

17:10:35,125 ERROR [org.jboss.msc.service.fail] (ServerService Thread Pool -- 51) MSC000001: Failed to start service jboss.persistenceunit."blueMonster.war#blueMonster": org.jboss.msc.service.StartException in service jboss.persistenceunit."blueMonster.war#blueMonster": javax.persistence.PersistenceException: [PersistenceUnit: blueMonster] Unable to build Hibernate SessionFactory
    at org.jboss.as.jpa.service.PersistenceUnitServiceImpl$1$1.run(PersistenceUnitServiceImpl.java:172) [wildfly-jpa-8.2.0.Final.jar:8.2.0.Final]
    at org.jboss.as.jpa.service.PersistenceUnitServiceImpl$1$1.run(PersistenceUnitServiceImpl.java:117) [wildfly-jpa-8.2.0.Final.jar:8.2.0.Final]
    at java.security.AccessController.doPrivileged(Native Method) [rt.jar:1.8.0_40]
    at org.wildfly.security.manager.WildFlySecurityManager.doChecked(WildFlySecurityManager.java:474)
    at org.jboss.as.jpa.service.PersistenceUnitServiceImpl$1.run(PersistenceUnitServiceImpl.java:182) [wildfly-jpa-8.2.0.Final.jar:8.2.0.Final]
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [rt.jar:1.8.0_40]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [rt.jar:1.8.0_40]
    at java.lang.Thread.run(Thread.java:745) [rt.jar:1.8.0_40]
    at org.jboss.threads.JBossThread.run(JBossThread.java:122) [jboss-threads-2.1.1.Final.jar:2.1.1.Final]
Caused by: javax.persistence.PersistenceException: [PersistenceUnit: blueMonster] Unable to build Hibernate SessionFactory
    at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.persistenceException(EntityManagerFactoryBuilderImpl.java:1239) [hibernate-entitymanager-4.3.7.Final.jar:4.3.7.Final]
    at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.access$600(EntityManagerFactoryBuilderImpl.java:120) [hibernate-entitymanager-4.3.7.Final.jar:4.3.7.Final]
    at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:855) [hibernate-entitymanager-4.3.7.Final.jar:4.3.7.Final]
    at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:845) [hibernate-entitymanager-4.3.7.Final.jar:4.3.7.Final]
    at org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl.withTccl(ClassLoaderServiceImpl.java:398) [hibernate-core-4.3.7.Final.jar:4.3.7.Final]
    at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:844) [hibernate-entitymanager-4.3.7.Final.jar:4.3.7.Final]
    at org.jboss.as.jpa.hibernate4.TwoPhaseBootstrapImpl.build(TwoPhaseBootstrapImpl.java:44) [jipijapa-hibernate4-3-1.0.1.Final.jar:]
    at org.jboss.as.jpa.service.PersistenceUnitServiceImpl$1$1.run(PersistenceUnitServiceImpl.java:154) [wildfly-jpa-8.2.0.Final.jar:8.2.0.Final]
    ... 8 more
Caused by: org.hibernate.MappingException: Could not get constructor for org.hibernate.persister.collection.OneToManyPersister
    at org.hibernate.persister.internal.PersisterFactoryImpl.create(PersisterFactoryImpl.java:253) [hibernate-core-4.3.7.Final.jar:4.3.7.Final]
    at org.hibernate.persister.internal.PersisterFactoryImpl.createCollectionPersister(PersisterFactoryImpl.java:201) [hibernate-core-4.3.7.Final.jar:4.3.7.Final]
    at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:430) [hibernate-core-4.3.7.Final.jar:4.3.7.Final]
    at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1859) [hibernate-core-4.3.7.Final.jar:4.3.7.Final]
    at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:852) [hibernate-entitymanager-4.3.7.Final.jar:4.3.7.Final]
    ... 13 more
Caused by: org.hibernate.HibernateException: Unable to parse order-by fragment
    at org.hibernate.sql.ordering.antlr.OrderByFragmentTranslator.translate(OrderByFragmentTranslator.java:69) [hibernate-core-4.3.7.Final.jar:4.3.7.Final]
    at org.hibernate.sql.Template.translateOrderBy(Template.java:728) [hibernate-core-4.3.7.Final.jar:4.3.7.Final]
    at org.hibernate.persister.collection.AbstractCollectionPersister.<init>(AbstractCollectionPersister.java:578) [hibernate-core-4.3.7.Final.jar:4.3.7.Final]
    at org.hibernate.persister.collection.OneToManyPersister.<init>(OneToManyPersister.java:89) [hibernate-core-4.3.7.Final.jar:4.3.7.Final]
    at sun.reflect.GeneratedConstructorAccessor32.newInstance(Unknown Source) [:1.8.0_40]
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) [rt.jar:1.8.0_40]
    at java.lang.reflect.Constructor.newInstance(Constructor.java:422) [rt.jar:1.8.0_40]
    at org.hibernate.persister.internal.PersisterFactoryImpl.create(PersisterFactoryImpl.java:231) [hibernate-core-4.3.7.Final.jar:4.3.7.Final]
    ... 17 more
Caused by: java.lang.ClassCastException: antlr.CommonToken cannot be cast to antlr.Token
    at antlr.CharScanner.makeToken(CharScanner.java:173) [antlr-2.7.7.jar:]
    at org.hibernate.sql.ordering.antlr.GeneratedOrderByLexer.mIDENT(GeneratedOrderByLexer.java:239) [hibernate-core-4.3.7.Final.jar:4.3.7.Final]
    at org.hibernate.sql.ordering.antlr.GeneratedOrderByLexer.nextToken(GeneratedOrderByLexer.java:139) [hibernate-core-4.3.7.Final.jar:4.3.7.Final]
    at antlr.TokenBuffer.fill(TokenBuffer.java:69) [antlr-2.7.7.jar:]
    at antlr.TokenBuffer.LA(TokenBuffer.java:80) [antlr-2.7.7.jar:]
    at antlr.LLkParser.LA(LLkParser.java:52) [antlr-2.7.7.jar:]
    at org.hibernate.sql.ordering.antlr.GeneratedOrderByFragmentParser.expression(GeneratedOrderByFragmentParser.java:565) [hibernate-core-4.3.7.Final.jar:4.3.7.Final]
    at org.hibernate.sql.ordering.antlr.GeneratedOrderByFragmentParser.sortKey(GeneratedOrderByFragmentParser.java:346) [hibernate-core-4.3.7.Final.jar:4.3.7.Final]
    at org.hibernate.sql.ordering.antlr.GeneratedOrderByFragmentParser.sortSpecification(GeneratedOrderByFragmentParser.java:241) [hibernate-core-4.3.7.Final.jar:4.3.7.Final]
    at org.hibernate.sql.ordering.antlr.GeneratedOrderByFragmentParser.orderByFragment(GeneratedOrderByFragmentParser.java:190) [hibernate-core-4.3.7.Final.jar:4.3.7.Final]
    at org.hibernate.sql.ordering.antlr.OrderByFragmentTranslator.translate(OrderByFragmentTranslator.java:63) [hibernate-core-4.3.7.Final.jar:4.3.7.Final]
    ... 24 more

如果我删除@OrderBy,它将运行正常。

经过一番挖掘后,我发现了一种解决方法,但我无法使用它,该解决方法是更改​​pom.xml并在hibernate核心依赖项上向antl添加排除项

    <dependency>
       <groupId>org.hibernate</groupId>
       <artifactId>hibernate-core</artifactId>
       <version>4.0.1.Final</version>
       <scope>provided</scope>

       <exclusions>
          <exclusion>
             <groupId>antlr</groupId>
             <artifactId>antlr</artifactId>
          </exclusion>
       </exclusions>
    </dependency>

我正在使用JPA,所以我的pom.xml上没有hibernate-core我对pom.xml的依赖是:

<dependencies>
        <dependency>
            <groupId>org.jboss.spec.javax.security.auth.message</groupId>
            <artifactId>jboss-jaspi-api_1.1_spec</artifactId>
            <version>1.0.0.Final</version>
        </dependency>
        <dependency>
            <groupId>org.jboss.spec.javax.security.jacc</groupId>
            <artifactId>jboss-jacc-api_1.5_spec</artifactId>
            <version>1.0.0.Final</version>
        </dependency>
        <dependency>
            <groupId>org.jboss.spec.javax.ejb</groupId>
            <artifactId>jboss-ejb-api_3.2_spec</artifactId>
            <version>1.0.0.Final</version>
        </dependency>
        <dependency>
            <groupId>org.hibernate.javax.persistence</groupId>
            <artifactId>hibernate-jpa-2.1-api</artifactId>
            <version>1.0.0.Final</version>
        </dependency>
        <dependency>
            <groupId>org.jboss.spec.javax.faces</groupId>
            <artifactId>jboss-jsf-api_2.2_spec</artifactId>
            <version>2.2.8</version>
        </dependency>
        <dependency>
            <groupId>org.jboss.spec.javax.interceptor</groupId>
            <artifactId>jboss-interceptors-api_1.2_spec</artifactId>
            <version>1.0.0.Final</version>
        </dependency>
        <dependency>
            <groupId>org.jboss.spec.javax.rmi</groupId>
            <artifactId>jboss-rmi-api_1.0_spec</artifactId>
            <version>1.0.4.Final</version>
        </dependency>
        <dependency>
            <groupId>javax.inject</groupId>
            <artifactId>javax.inject</artifactId>
            <version>1</version>
        </dependency>
        <dependency>
            <groupId>org.jboss.spec.javax.resource</groupId>
            <artifactId>jboss-connector-api_1.7_spec</artifactId>
            <version>1.0.0.Final</version>
        </dependency>
        <dependency>
            <groupId>org.jboss.resteasy</groupId>
            <artifactId>jaxrs-api</artifactId>
            <version>3.0.10.Final</version>
        </dependency>
        <dependency>
            <groupId>org.jboss.spec.javax.xml.bind</groupId>
            <artifactId>jboss-jaxb-api_2.2_spec</artifactId>
            <version>1.0.4.Final</version>
        </dependency>
        <dependency>
            <groupId>org.jboss.spec.javax.xml.rpc</groupId>
            <artifactId>jboss-jaxrpc-api_1.1_spec</artifactId>
            <version>1.0.1.Final</version>
        </dependency>
        <dependency>
            <groupId>org.jboss.spec.javax.xml.ws</groupId>
            <artifactId>jboss-jaxws-api_2.2_spec</artifactId>
            <version>2.0.2.Final</version>
        </dependency>
        <dependency>
            <groupId>org.jboss.spec.javax.xml.soap</groupId>
            <artifactId>jboss-saaj-api_1.3_spec</artifactId>
            <version>1.0.3.Final</version>
        </dependency>
        <dependency>
            <groupId>wsdl4j</groupId>
            <artifactId>wsdl4j</artifactId>
            <version>1.6.3</version>
        </dependency>
        <dependency>
            <groupId>org.jboss.spec.javax.jms</groupId>
            <artifactId>jboss-jms-api_2.0_spec</artifactId>
            <version>1.0.0.Final</version>
        </dependency>
        <dependency>
            <groupId>org.jboss.spec.javax.management.j2ee</groupId>
            <artifactId>jboss-j2eemgmt-api_1.1_spec</artifactId>
            <version>1.0.1.Final</version>
        </dependency>
        <dependency>
            <groupId>org.jboss.spec.javax.transaction</groupId>
            <artifactId>jboss-transaction-api_1.2_spec</artifactId>
            <version>1.0.0.Final</version>
        </dependency>
        <dependency>
            <groupId>javax.jws</groupId>
            <artifactId>jsr181-api</artifactId>
            <version>1.0-MR1</version>
        </dependency>
        <dependency>
            <groupId>com.sun.mail</groupId>
            <artifactId>javax.mail</artifactId>
            <version>1.5.1</version>
        </dependency>
        <dependency>
            <groupId>javax.enterprise</groupId>
            <artifactId>cdi-api</artifactId>
            <version>1.1</version>
        </dependency>
        <dependency>
            <groupId>org.jboss.spec.javax.servlet.jstl</groupId>
            <artifactId>jboss-jstl-api_1.2_spec</artifactId>
            <version>1.1.2.Final</version>
        </dependency>
        <dependency>
            <groupId>org.jboss.spec.javax.servlet.jsp</groupId>
            <artifactId>jboss-jsp-api_2.3_spec</artifactId>
            <version>1.0.1.Final</version>
        </dependency>
        <dependency>
            <groupId>org.jboss.spec.javax.servlet</groupId>
            <artifactId>jboss-servlet-api_3.1_spec</artifactId>
            <version>1.0.0.Final</version>
        </dependency>
        <dependency>
            <groupId>javax.activation</groupId>
            <artifactId>activation</artifactId>
            <version>1.1.1</version>
        </dependency>
        <dependency>
            <groupId>javax.validation</groupId>
            <artifactId>validation-api</artifactId>
            <version>1.1.0.Final</version>
        </dependency>
        <dependency>
            <groupId>org.jboss.spec.javax.annotation</groupId>
            <artifactId>jboss-annotations-api_1.2_spec</artifactId>
            <version>1.0.0.Final</version>
        </dependency>
        <dependency>
            <groupId>org.jboss.spec.javax.el</groupId>
            <artifactId>jboss-el-api_3.0_spec</artifactId>
            <version>1.0.3.Final</version>
        </dependency>
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-validator</artifactId>
            <version>5.1.3.Final</version>
        </dependency>
        <dependency>
            <groupId>org.picketbox</groupId>
            <artifactId>picketbox</artifactId>
            <version>4.0.21.Final</version>

            <exclusions>
    <exclusion>
      <groupId>org.picketbox</groupId>
      <artifactId>picketbox-spi-bare</artifactId>
    </exclusion>
    <exclusion>
      <groupId>org.picketbox</groupId>
      <artifactId>jbosssx-bare</artifactId>
    </exclusion>
    <exclusion>
      <groupId>org.jboss.logging</groupId>
      <artifactId>jboss-logging-spi</artifactId>
    </exclusion>
    <exclusion>
      <groupId>org.infinispan</groupId>
      <artifactId>infinispan-core</artifactId>
    </exclusion>
  </exclusions>


        </dependency>
        <dependency>
            <groupId>org.picketbox</groupId>
            <artifactId>picketbox-commons</artifactId>
            <version>1.0.0.final</version>
        </dependency>
        <dependency>
            <groupId>org.picketbox</groupId>
            <artifactId>picketbox-infinispan</artifactId>
            <version>4.0.21.Final</version>
        </dependency>
        <dependency>
            <groupId>org.wildfly</groupId>
            <artifactId>wildfly-controller-client</artifactId>
            <version>8.2.0.Final</version>
        </dependency>
        <dependency>
            <groupId>org.jboss</groupId>
            <artifactId>jboss-dmr</artifactId>
            <version>1.2.0.Final</version>
        </dependency>
        <dependency>
            <groupId>org.jboss.logging</groupId>
            <artifactId>jboss-logging</artifactId>
            <version>3.1.4.GA</version>
        </dependency>
        <dependency>
            <groupId>org.jboss.resteasy</groupId>
            <artifactId>resteasy-jaxb-provider</artifactId>
            <version>3.0.10.Final</version>
        </dependency>
        <dependency>
            <groupId>org.jboss.resteasy</groupId>
            <artifactId>async-http-servlet-3.0</artifactId>
            <version>3.0.10.Final</version>
        </dependency>
        <dependency>
            <groupId>org.jboss.resteasy</groupId>
            <artifactId>resteasy-client</artifactId>
            <version>3.0.10.Final</version>
        </dependency>
        <dependency>
            <groupId>org.jboss.resteasy</groupId>
            <artifactId>resteasy-jaxrs</artifactId>
            <version>3.0.10.Final</version>
        </dependency>
        <dependency>
            <groupId>org.jboss.resteasy</groupId>
            <artifactId>resteasy-multipart-provider</artifactId>
            <version>3.0.10.Final</version>
        </dependency>
        <dependency>
            <groupId>org.jboss.ejb3</groupId>
            <artifactId>jboss-ejb3-ext-api</artifactId>
            <version>2.1.0</version>
        </dependency>
        <dependency>
            <groupId>org.primefaces</groupId>
            <artifactId>primefaces</artifactId>
            <version>5.2</version>
        </dependency>
        <dependency>
            <groupId>org.primefaces.themes</groupId>
            <artifactId>all-themes</artifactId>
            <version>1.0.10</version>
        </dependency>
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-infinispan</artifactId>
            <version>4.2.1.Final</version>

             <exclusions>
    <exclusion>
      <groupId>org.hibernate</groupId>
      <artifactId>hibernate-core</artifactId>
    </exclusion>
  </exclusions>


        </dependency>
        <dependency>
            <groupId>org.webjars</groupId>
            <artifactId>font-awesome</artifactId>
            <version>4.3.0</version>
        </dependency>
        <dependency>
            <groupId>org.omnifaces</groupId>
            <artifactId>omnifaces</artifactId>
            <version>2.0</version>
        </dependency>
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-lang3</artifactId>
            <version>3.3.2</version>
        </dependency>
        <dependency>
            <groupId>commons-fileupload</groupId>
            <artifactId>commons-fileupload</artifactId>
            <version>1.3.1</version>
        </dependency>
        <dependency>
            <groupId>commons-io</groupId>
            <artifactId>commons-io</artifactId>
            <version>2.4</version>
        </dependency>
        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi</artifactId>
            <version>3.10.1</version>
        </dependency>
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-java</artifactId>
            <version>2.45.0</version>
        </dependency>
        <dependency>
            <groupId>net.sf.opencsv</groupId>
            <artifactId>opencsv</artifactId>
            <version>2.3</version>
        </dependency>
        <dependency>
            <groupId>xml-apis</groupId>
            <artifactId>xml-apis</artifactId>
            <version>1.4.01</version>
        </dependency>
        <dependency>
            <groupId>org.apache.httpcomponents</groupId>
            <artifactId>httpclient</artifactId>
            <version>4.3.6</version>
        </dependency>
        <dependency>
            <groupId>org.apache.httpcomponents</groupId>
            <artifactId>httpcore</artifactId>
            <version>4.3.3</version>
        </dependency>
        <dependency>
            <groupId>com.byteslounge</groupId>
            <artifactId>cdi-properties</artifactId>
            <version>1.0.0</version>
        </dependency>
        <dependency>
            <groupId>org.apache.deltaspike.core</groupId>
            <artifactId>deltaspike-core-api</artifactId>
            <version>1.2.1</version>
        </dependency>
        <dependency>
            <groupId>org.apache.deltaspike.core</groupId>
            <artifactId>deltaspike-core-impl</artifactId>
            <version>1.2.1</version>
            <scope>runtime</scope>
        </dependency>
    </dependencies>

我正在使用Wildfly,如何解决此问题?

阅读@GuillermoFernández答复后,我做了以下工作:

mvn dependency:tree -Dincludes=antlr

结果是:

[INFO] blueMonster:blueMonster:war:0.0.1-SNAPSHOT
[INFO] \- org.hibernate:hibernate-infinispan:jar:4.2.1.Final:compile
[INFO]    \- org.hibernate:hibernate-core:jar:4.2.1.Final:compile
[INFO]       \- antlr:antlr:jar:2.7.7:compile

按照他的步骤,我还更新了pom.xml,但是由于错误的发生,还有其他原因也会导致该错误,我该如何识别必须排除的错误?

我的@OrderBy

@OrderBy("data") 
@OneToMany(cascade = CascadeType.ALL, mappedBy = "csr")
    private List<CsrSeveridadeLog> severidadeLogList;

问题答案:

经过几次排除尝试后,我解决了添加问题

-DANTLR_USE_DIRECT_CLASS_LOADING=true


 类似资料:
  • 我使用以下源代码创建了自己的SDF模式:https://docs.oracle.com/en/java/javase/13/docs/api/java.base/java/text/simpledateformat.html 导致以下错误,我不明白原因: 任何帮助都会很棒! 编辑:我正在使用JDK 13 进程结束,退出代码为%1

  • 问题内容: 以下是引发异常的代码段: 上面的代码在2:00 AM之后的所有日期均抛出异常,它一直运行到01:30 AM 已配置夏令时(我正在使用时区)。 之后,我可能会看到3:00 AM的日志也没有记录在2:00 AM和3:00 AM之间的时间。 日志: 10月01日03:02:01错误:无法解析的日期:“ 201710010200” 引起原因:java.text.ParseException:无

  • 问题内容: 出于某种原因,在完成了Phonegap的非包含性说明(甚至没有提到设置ANT,或者没有遇到Ant和JDK的麻烦)之后,这根本不起作用: 它给出了5个错误,指出无法解析org.apache.cordova的事实。我完全确定此时该怎么办。请帮忙。这是在尝试使sdk正常工作并最终能够在eclipse中打开项目的3个小时之后。按照他们的文档中的步骤进行操作后,除非能弄清楚,否则我将浪费3个小时

  • 问题内容: 我在用macOS 10.13.5编写的MacBookPro上安装了Eclipse [Version:Photon Release(4.8.0)]和JDK 10。 我得到错误: 导入java.awt无法解析 是包含在JDK 10?如果是,在哪里,如何使Eclipse可见?如果没有,如何添加java.awt? 问题答案: 是包含在JDK 10? 是的,包裹确实存在。Java10 API文档

  • 问题内容: 我有一个问题,日食说它找不到javax.ejb.Schedule(或时间表),但与其他类(如javax.ejb.MessageDriven)没有问题。我正在处理一个我不太了解的大型应用程序。所以我的问题是如何解决这个问题?还是寻找方法? 问题答案: JBoos 4是兼容JEE5的服务器,因此JEE6功能不可用。

  • 问题内容: 我正在尝试使用 Eclipse for Java EE 开发Web应用程序。 我需要使用 Tomcat 作为 服务器 。我已经下载了Tomcat并且它正在运行。但是我的程序无法编译。 我收到以下错误: 导入javax.servlet无法解析。 我需要做什么? 问题答案: 您需要将Servlet API添加到类路径中。在Tomcat 6.0中,它位于Tomcat 文件夹中的JAR 中。您