ClassNotFoundException: org.hibernate.hql.internal.ast.HqlToken even after adding classic.ClassicQueryTranslatorFactory

Jacob picture Jacob · Dec 21, 2012 · Viewed 7.9k times · Source

Possible Duplicate:
org.hibernate.HibernateException: could not instantiate QueryTranslatorFactory: org.hibernate.hql.classic.ClassicQueryTransactionFactory

I am using Hibernate 4, Spring 3 and JSF 2.0. While running jsf page I am getting

org.hibernate.QueryException: ClassNotFoundException: 
org.hibernate.hql.internal.ast.HqlToken [select generatedAlias0 from 
net.test.model.Request as generatedAlias0]

I already have the following under hibernate properties in applicationContext.xml

<prop key="hibernate.query.factory_class">org.hibernate.hql.internal.classic.
ClassicQueryTranslatorFactory
                </prop>

Please note that I have added org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean and org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter, I suspect that after adding this I was again getting org.hibernate.QueryException: ClassNotFoundException

My question what is the equivalent of ClassicQueryTranslatorFactory for spring properties? If no such properties how could I resolve this?

applicationContext.xml

<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tx="http://www.springframework.org/schema/tx"
    xmlns:context="http://www.springframework.org/schema/context"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd">
    <!-- Spring view scope customized -->

    <bean class="org.springframework.beans.factory.config.CustomScopeConfigurer">
        <property name="scopes">
            <map>
                <entry key="view">
                    <bean class="org.primefaces.spring.scope.ViewScope" />
                </entry>
            </map>
        </property>
    </bean>
    <context:component-scan base-package="net.test" />
    <!-- Data Source Declaration -->
    <bean id="DataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"
        destroy-method="close">
        <property name="driverClass" value="oracle.jdbc" />
        <property name="jdbcUrl"
            value="jdbc:oracle:thin:@server:1521:orcl" />
        <property name="user" value="scott" />
        <property name="password" value="tiger" />
        <property name="maxPoolSize" value="10" />
        <property name="maxStatements" value="0" />
        <property name="minPoolSize" value="5" />
    </bean>
      <bean class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor"/>
    <!-- JPA Entity Manager Factory -->
    <bean id="entityManagerFactory" 
          class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"> 
         <property name="dataSource" ref="DataSource" />
         <property name="packagesToScan" value="net.test.model" />

         <property name="jpaVendorAdapter">      
      <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">  
      <property name="showSql" value="false" />
         <property name="generateDdl" value="false" />
         <property name="databasePlatform" value="${jdbc.dialectClass}" />            
       </bean>
   </property>         
      </bean> 
      <bean id="defaultLobHandler" class="org.springframework.jdbc.support.lob.DefaultLobHandler" />        
    <!-- Session Factory Declaration -->
    <bean id="SessionFactory"
        class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
        <property name="dataSource" ref="DataSource" />
        <property name="annotatedClasses">
            <list>
                <value>net.test.model.Request</value>
            </list>
        </property>
        <property name="hibernateProperties">
            <props>
                <prop key="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect</prop>
                <prop key="hibernate.show_sql">true</prop>
                <prop key="hibernate.query.factory_class">org.hibernate.hql.internal.classic.ClassicQueryTranslatorFactory
                </prop>
            </props>
        </property>
    </bean>
    <!-- Enable the configuration of transactional behavior based on annotations 
    <tx:annotation-driven transaction-manager="txManager" />-->
    <!-- Transaction Manager is defined 
    <bean id="txManager"
        class="org.springframework.orm.hibernate4.HibernateTransactionManager">
        <property name="sessionFactory" ref="SessionFactory" />
    </bean>-->

     <!-- Transaction Config -->
    <bean id="transactionManager"
          class="org.springframework.orm.jpa.JpaTransactionManager">
          <property name="entityManagerFactory" ref="entityManagerFactory" />
          </bean>   

          <bean id="txManager"
        class="org.springframework.orm.hibernate4.HibernateTransactionManager">
        <property name="sessionFactory" ref="SessionFactory" />
    </bean>         

    <tx:annotation-driven transaction-manager="transactionManager"/>  
    <tx:annotation-driven transaction-manager="txManager"/>             

     <context:annotation-config/>


    <bean id="hibernateStatisticsMBean" class="org.hibernate.jmx.StatisticsService">
        <property name="statisticsEnabled" value="true" />
        <property name="sessionFactory" value="#{entityManagerFactory.sessionFactory}" />
    </bean>
    <bean name="ehCacheManagerMBean"
        class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean" />

    <bean id="mbeanServer" class="org.springframework.jmx.support.MBeanServerFactoryBean">
        <property name="locateExistingServerIfPossible" value="true" />
    </bean>

    <bean id="jmxExporter" class="org.springframework.jmx.export.MBeanExporter" lazy-init="false">
        <property name="server" ref="mbeanServer" />
        <property name="registrationBehaviorName" value="REGISTRATION_REPLACE_EXISTING"/>
        <property name="beans">
            <map>               
                <entry key="SpringBeans:name=hibernateStatisticsMBean" value-ref="hibernateStatisticsMBean" />
                <entry key="SpringBeans:name=ehCacheManagerMBean" value-ref="ehCacheManagerMBean" />
            </map>
        </property>
    </bean>

</beans>

Answer

Harish Raj picture Harish Raj · Dec 21, 2012

edit modules/org/antlr/main/module.xml by adding the line <module name="org.hibernate" optional="true"/> inside the <dependencies> section. The issue must be resolved.

Thank you.