2

可能重复:
org.hibernate.HibernateException:无法实例化 QueryTranslatorFactory:org.hibernate.hql.classic.ClassicQueryTransactionFactory

我正在使用 Hibernate 4、Spring 3 和 JSF 2.0。在运行 jsf 页面时,我得到了

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

我在 applicationContext.xml 的休眠属性下已经有了以下内容

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

请注意,我添加了org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBeanand org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter,我怀疑添加后我又得到了org.hibernate.QueryException: ClassNotFoundException

我的问题是什么相当于ClassicQueryTranslatorFactory弹簧属性?如果没有这样的属性,我怎么能解决这个问题?

应用程序上下文.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>
4

2 回答 2

1

通过执行以下操作已解决此问题

使用antlr 2.7.6与 Hibernate 兼容的版本,在setDomainEnv.cmd

set CLASSPATH=\maven\repo\antlr\antlr\2.7.6\antlr-2.7.6.jar;%CLASSPATH%

更多信息在这里

谢谢

于 2012-12-22T03:58:24.820 回答
1

通过在部分内添加行来编辑modules/org/antlr/main/module.xml。这个问题必须解决。<module name="org.hibernate" optional="true"/><dependencies>

谢谢你。

于 2012-12-21T10:25:16.683 回答