-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 
Author Message
 Post subject: ClassCastException: antlr.CommonToken cannot be cast to antl
PostPosted: Wed Feb 29, 2012 7:23 pm 
Newbie

Joined: Wed Feb 29, 2012 7:05 pm
Posts: 1
Hi,
I'm trying to incorporate Hibernate Search 4.0.0.Final into a Java EE 6 project, with Seam 3 using JBoss AS 7.0.2.Final (Web Profile).
In my POM I have the following:

Code:
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-search</artifactId>
            <version>4.0.0.Final</version>
        </dependency>

        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-core</artifactId>
            <version>4.0.1.Final</version>
        </dependency>
       
        <!-- if using JPA (2) -->
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-entitymanager</artifactId>
            <version>4.0.1.Final</version>
        </dependency>   


I've set up my persistence.xml etc, but I get the following runtime error:

Code:
Caused by: javax.persistence.PersistenceException: [PersistenceUnit: myPU] Unable to build EntityManagerFactory
   at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:908)
   at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:884)
   at org.hibernate.ejb.HibernatePersistence.createContainerEntityManagerFactory(HibernatePersistence.java:73)
   at org.jboss.as.jpa.service.PersistenceUnitService.createContainerEntityManagerFactory(PersistenceUnitService.java:143)
   at org.jboss.as.jpa.service.PersistenceUnitService.start(PersistenceUnitService.java:77)
   at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1824) [jboss-msc-1.0.1.GA.jar:1.0.1.GA]
   at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1759) [jboss-msc-1.0.1.GA.jar:1.0.1.GA]
   ... 3 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:248)
   at org.hibernate.persister.internal.PersisterFactoryImpl.createCollectionPersister(PersisterFactoryImpl.java:196)
   at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:370)
   at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1722)
   at org.hibernate.ejb.EntityManagerFactoryImpl.<init>(EntityManagerFactoryImpl.java:76)
   at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:899)
   ... 9 more
Caused by: org.hibernate.HibernateException: Unable to parse order-by fragment
   at org.hibernate.sql.ordering.antlr.OrderByFragmentTranslator.render(OrderByFragmentTranslator.java:66)
   at org.hibernate.sql.Template.renderOrderByStringTemplate(Template.java:695)
   at org.hibernate.persister.collection.AbstractCollectionPersister.<init>(AbstractCollectionPersister.java:559)
   at org.hibernate.persister.collection.OneToManyPersister.<init>(OneToManyPersister.java:84)
   at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) [:1.7.0]
   at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57) [:1.7.0]
   at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) [:1.7.0]
   at java.lang.reflect.Constructor.newInstance(Constructor.java:525) [:1.7.0]
   at org.hibernate.persister.internal.PersisterFactoryImpl.create(PersisterFactoryImpl.java:226)
   ... 14 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:238)
   at org.hibernate.sql.ordering.antlr.GeneratedOrderByLexer.nextToken(GeneratedOrderByLexer.java:138)
   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:504)
   at org.hibernate.sql.ordering.antlr.GeneratedOrderByFragmentParser.sortKey(GeneratedOrderByFragmentParser.java:325)
   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.render(OrderByFragmentTranslator.java:60)


In my list of dependencies I see I'm using antlr-2.7.7.jar. Does anyone know what's happening here?

Many thanks.


Top
 Profile  
 
 Post subject: Re: ClassCastException: antlr.CommonToken cannot be cast to antl
PostPosted: Mon Mar 05, 2012 12:51 pm 
Newbie

Joined: Mon Mar 05, 2012 12:37 pm
Posts: 2
I encountered a similar problem, though for a different reason. I'm not 100% sure, but the issue seems to be caused by the fact that explicitly putting Hibernate on the classpath using Maven conflicts with JBoss 7 when it automatically adds Hibernate as a dependency, due to the strict classloading system AS7 employs. I think the problem is that two ANTLR JARs end up on the classpath, and even though they're the same JAR, they're loaded separately which in turn means their classes are defined separately. So if you try to pass an object created by one JAR to something using the other JAR, you get a ClassCastException because they're technically not the same class and don't share the same inheritance hierarchy.

Fortunately, there's an easy workaround. For starters, unless you have explicit compile-time dependencies on Hibernate (versus just JPA), don't declare Hibernate as a dependency in your POM. Use this instead:
Code:
<dependency>
   <groupId>org.jboss.spec</groupId>
   <artifactId>jboss-javaee-6.0</artifactId>
   <version>3.0.0.Beta1</version>
   <type>pom</type>
   <scope>provided</scope>
</dependency>

This will make all the EE stuff available at compile time, but will not add it to the classpath at runtime due to the provided scope, where JBoss will provide it instead.

If, for some reason, you do have an explicit compile-time dependency on Hibernate, do this:
Code:
<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>


Adding the exclusion fixes the problem for me.


Top
 Profile  
 
 Post subject: Re: ClassCastException: antlr.CommonToken cannot be cast to antl
PostPosted: Wed Jun 06, 2012 4:15 pm 
Newbie

Joined: Thu Jan 14, 2010 12:33 pm
Posts: 4
@Newbie

very helpful post, thank you, i had same problem and
took your 2nd suggestion to apply exclusion


Top
 Profile  
 
 Post subject: Re: ClassCastException: antlr.CommonToken cannot be cast to antl
PostPosted: Fri May 02, 2014 5:55 am 
Newbie

Joined: Tue Apr 29, 2014 10:36 pm
Posts: 2
Hi,

I encounter same issue when migrating seam 2.2 (hibernate 3 + jsf 1.2 + richfaces 3.x.x + JBOSS AS5) to seam 2.3 (hibernate 4 + jsf 2 + richfaces 4 + JBOSS AS7).
Pls help...

BIG THANKS~! \m/


Top
 Profile  
 
 Post subject: Re: ClassCastException: antlr.CommonToken cannot be cast to antl
PostPosted: Fri Feb 13, 2015 10:22 am 
Newbie

Joined: Fri Feb 13, 2015 10:19 am
Posts: 1
Thank you!


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.