2 Replies Latest reply on Oct 21, 2015 11:33 AM by Michael Awizen

    HibernateException: Unable to parse order-by fragment on Wildfly 9

    Michael Awizen Novice

      Hi everybody,

       

      after a migration from Wildfly 8 to Wildfly 9 I'm not able to deploy my JPA Application any more:

       

      15:21:44,669 ERROR [org.jboss.msc.service.fail] (ServerService Thread Pool -- 86) MSC000001: Failed to start service jboss.persistenceunit."gangehi-ear.ear/gangehi-model-ejb.jar#primary": org.jboss.msc.service.StartException in service jboss.persistenceunit."gangehi-ear.ear/gangehi-model-ejb.jar#primary": javax.persistence.PersistenceException: [PersistenceUnit: primary] Unable to build Hibernate SessionFactory
          at org.jboss.as.jpa.service.PersistenceUnitServiceImpl$1$1.run(PersistenceUnitServiceImpl.java:172)
          at org.jboss.as.jpa.service.PersistenceUnitServiceImpl$1$1.run(PersistenceUnitServiceImpl.java:117)
          at org.wildfly.security.manager.WildFlySecurityManager.doChecked(WildFlySecurityManager.java:665)
          at org.jboss.as.jpa.service.PersistenceUnitServiceImpl$1.run(PersistenceUnitServiceImpl.java:182)
          at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
          at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
          at java.lang.Thread.run(Thread.java:745)
          at org.jboss.threads.JBossThread.run(JBossThread.java:320)
      Caused by: javax.persistence.PersistenceException: [PersistenceUnit: primary] Unable to build Hibernate SessionFactory
          at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.persistenceException(EntityManagerFactoryBuilderImpl.java:1249)
          at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.access$600(EntityManagerFactoryBuilderImpl.java:120)
          at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:860)
          at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:850)
          at org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl.withTccl(ClassLoaderServiceImpl.java:425)
          at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:849)
          at org.jboss.as.jpa.hibernate4.TwoPhaseBootstrapImpl.build(TwoPhaseBootstrapImpl.java:44)
          at org.jboss.as.jpa.service.PersistenceUnitServiceImpl$1$1.run(PersistenceUnitServiceImpl.java:154)
          ... 7 more
      Caused by: org.hibernate.MappingException: Could not get constructor for org.hibernate.persister.collection.BasicCollectionPersister
          at org.hibernate.persister.internal.PersisterFactoryImpl.create(PersisterFactoryImpl.java:253)
          at org.hibernate.persister.internal.PersisterFactoryImpl.createCollectionPersister(PersisterFactoryImpl.java:201)
          at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:430)
          at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1859)
          at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:857)
          ... 12 more
      Caused by: org.hibernate.HibernateException: Unable to parse order-by fragment
          at org.hibernate.sql.ordering.antlr.OrderByFragmentTranslator.translate(OrderByFragmentTranslator.java:69)
          at org.hibernate.sql.Template.translateOrderBy(Template.java:729)
          at org.hibernate.persister.collection.AbstractCollectionPersister.<init>(AbstractCollectionPersister.java:604)
          at org.hibernate.persister.collection.BasicCollectionPersister.<init>(BasicCollectionPersister.java:77)
          at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
          at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
          at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
          at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
          at org.hibernate.persister.internal.PersisterFactoryImpl.create(PersisterFactoryImpl.java:231)
          ... 16 more
      Caused by: java.lang.ClassCastException: antlr.CommonToken cannot be cast to antlr.Token
          at antlr.CharScanner.makeToken(CharScanner.java:173)
          at org.hibernate.sql.ordering.antlr.GeneratedOrderByLexer.mIDENT(GeneratedOrderByLexer.java:239)
          at org.hibernate.sql.ordering.antlr.GeneratedOrderByLexer.nextToken(GeneratedOrderByLexer.java:139)
          at antlr.TokenBuffer.fill(TokenBuffer.java:69)
          at antlr.TokenBuffer.LA(TokenBuffer.java:80)
          at antlr.LLkParser.LA(LLkParser.java:52)
          at org.hibernate.sql.ordering.antlr.GeneratedOrderByFragmentParser.expression(GeneratedOrderByFragmentParser.java:565)
          at org.hibernate.sql.ordering.antlr.GeneratedOrderByFragmentParser.sortKey(GeneratedOrderByFragmentParser.java:346)
          at org.hibernate.sql.ordering.antlr.GeneratedOrderByFragmentParser.sortSpecification(GeneratedOrderByFragmentParser.java:241)
          at org.hibernate.sql.ordering.antlr.GeneratedOrderByFragmentParser.orderByFragment(GeneratedOrderByFragmentParser.java:190)
          at org.hibernate.sql.ordering.antlr.OrderByFragmentTranslator.translate(OrderByFragmentTranslator.java:63)
          ... 24 more
      

       

       

      My dependency management in the parent pom consists basically of this:

       

      <dependencyManagement>
      
          <dependencies>
              
              <!-- JBoss BOM -->
              <dependency>
                  <groupId>org.wildfly</groupId>
                  <artifactId>wildfly-parent</artifactId>
                  <version>9.0.1.Final</version>
                  <type>pom</type>
                  <scope>import</scope>
              </dependency>
      
              <dependency>
                  <groupId>org.jboss.arquillian</groupId>
                  <artifactId>arquillian-bom</artifactId>
                  <version>1.1.9.Final</version>
              </dependency>
      
              <!-- define drools BOM -->
              <dependency>
                  <groupId>org.drools</groupId>
                  <artifactId>drools-bom</artifactId>
                  <type>pom</type>
                  <version>6.3.0.Final</version>
                  <scope>import</scope>
              </dependency>
          
              <!-- define jbpm BOM -->
              <dependency>
                  <groupId>org.jbpm</groupId>
                  <artifactId>jbpm-bom</artifactId>
                  <type>pom</type>
                  <version>6.3.0.Final</version>
                  <scope>import</scope>
              </dependency>
      
          </dependencies>
      </dependencyManagement>
      

       

       

      The workaround I found is to add antlr to the dependency management and to give it the scope provided:

       

       

      <dependency>
          <groupId>antlr</groupId>
          <artifactId>antlr</artifactId>
          <version>2.7.7</version>
          <scope>provided</scope>
      </dependency>
      

       

      But this is a kind of dirty workaround.

       

      How to deal with this problem properly?

       

      Especially, what is the recommended BOM for Wildfly 9?

        • 1. Re: HibernateException: Unable to parse order-by fragment on Wildfly 9
          Tomaz Cerar Master

          Michael Awizen wrote:

           


          My dependency management in the parent pom consists basically of this:

           

          1. <dependencyManagement> 
          2.  
          3.     <dependencies> 
          4.          
          5.         <!-- JBoss BOM --> 
          6.         <dependency> 
          7.             <groupId>org.wildfly</groupId> 
          8.             <artifactId>wildfly-parent</artifactId> 
          9.             <version>9.0.1.Final</version> 
          10.             <type>pom</type> 
          11.             <scope>import</scope> 
          12.         </dependency> 

           

           

          Especially, what is the recommended BOM for Wildfly 9?

          Never *ever* use wildfly-parent pom as import for your project. This will bring all dependencies that are used to build wildfly itself into your project.

           

          you should be using boms that are purposely made for consumption in user applications.

          see Releases · wildfly/boms · GitHub for details.

           

          something along lines of

          <dependency> 

              <groupId>org.wildfly.bom</groupId>

              <artifactId>jboss-javaee-7.0-wildfly</artifactId>

              <version>9.0.1.Final</version>

              <type>pom</type> 

              <scope>import</scope> 

          </dependency> 

           

          or if you are using arquillian as well, use jboss-javaee-7.0-wildfly-with-tools as artifact to import.

          • 2. Re: HibernateException: Unable to parse order-by fragment on Wildfly 9
            Michael Awizen Novice

            Thank you very much for the quick response! Now I have to review my dependencies in the subprojects.