2016-11-17 18 views
0

私のプロジェクトではspring data JPAHibernateのリミックスを使用します。 最近、パフォーマンスの問題が発生しました。 2番目のレベルのキャッシュ用にHibernateアノテーション@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)をエンティティクラスに追加したいと思います。 tomcatを起動すると、Second-level cache is used in the application, but property hibernate.cache.region.factory_class is not given, please either disable second level cache or set correct region factory class name to property hibernate.cache.region.factory_class (and make sure the second level cache provider, hibernate-infinispan, for example, is available in the classpath).がスローされます。Hibernate + Spring Data JPA第2レベルキャッシュXML

私の春-jpa.mxl

<?xml version="1.0" encoding="UTF-8"?> 
<beans xmlns="http://www.springframework.org/schema/beans" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mvc="http://www.springframework.org/schema/mvc" 
    xmlns:context="http://www.springframework.org/schema/context" 
    xmlns:jee="http://www.springframework.org/schema/jee" xmlns:jpa="http://www.springframework.org/schema/data/jpa" 
    xmlns:tx="http://www.springframework.org/schema/tx" 
    xsi:schemaLocation="http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee.xsd 
    http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd 
    http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd 
    http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd 
    http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa.xsd 
    http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd"> 
     <!-- use annotation in Service: @Transactional --> 

    <bean id="transactionManager2" class="org.springframework.orm.hibernate4.HibernateTransactionManager"> 
     <property name="sessionFactory" ref="sessionFactory" /> 
     <qualifier value="transactionManager2"/> 
    </bean> 

    <bean id="oracleConnection" class="org.springframework.jndi.JndiObjectFactoryBean"> 
     <property name="jndiName"> 
      <value>java:comp/env/jdbc/OracleDB</value> 
     </property> 
    </bean> 

    <bean id="oracleTransactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> 
     <property name="dataSource" ref="oracleConnection" /> 
     <qualifier value="oracleConnectionTransactionManager"/> 
    </bean> 



    <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager" /> 

    <tx:annotation-driven transaction-manager="transactionManager" /> 
    <bean id="mssqlDataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"> 
     <property name="driverClassName" value="com.microsoft.sqlserver.jdbc.SQLServerDriver" /> 
     <property name="url"> 
      <value>${connection.url}</value> 
     </property> 
     <property name="username"> 
      <value>${connection.username}</value> 
     </property> 
     <property name="password"> 
      <value>${[email protected]}</value> 
     </property>  
    </bean> 


    <bean id="auditInterceptor" class="com.bot.gnweb.unit.AuditIntercepter"/> 

    <bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean" destroy-method="destroy"> 
     <property name="dataSource" ref="mssqlDataSource" /> 
     <property name="entityInterceptor" ref="auditInterceptor"/> 
     <property name="packagesToScan"> 
      <value>com.bot.gnweb.model</value> 
     </property> 
     <property name="mappingResources"> 
      <list> 
       <value>gnwebSql.xml</value> 
      </list> 
     </property> 
     <property name="hibernateProperties"> 
      <props> 
       <prop key="hibernate.dialect">org.hibernate.dialect.SQLServerDialect</prop> 
       <prop key="hibernate.dialect">com.bot.gnweb.model.MssqlCustomDialect</prop> 
       <prop key="hibernate.cache.use_second_level_cache">true</prop> 
       <prop key="hibernate.cache.use_query_cache">true</prop> 
       <prop key="net.sf.ehcache.configurationResourceName">ehcache.xml</prop> 
       <prop key="hibernate.cache.region.factory_class">org.hibernate.cache.ehcache.EhCacheRegionFactory</prop> 
       <prop key="hibernate.generate_statistics">true</prop> 
      </props> 
     </property> 
    </bean> 



    <bean 
     class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" /> 

    <bean id="entityManagerFactory" 
     class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean" depends-on="auditInterceptor"> 
     <property name="persistenceProviderClass" value="org.hibernate.ejb.HibernatePersistence" /> 
     <property name="persistenceUnitName" value="gnWebPU" /> 
     <property name="dataSource" ref="mssqlDataSource" /> 
     <property name="persistenceXmlLocation" value="classpath:META-INF/persistence.xml" /> 
    </bean> 

    <!-- Spring Data --> 
    <jpa:repositories base-package="com.bot.gnweb.repository" 
     entity-manager-factory-ref="entityManagerFactory" 
     transaction-manager-ref="transactionManager" /> 

    <bean id="auditorBean" class="com.bot.gnweb.model.AuditingAware" /> 
    <jpa:auditing auditor-aware-ref="auditorBean" /> 


</beans> 

と私のpersistence.xmlの

<?xml version="1.0" encoding="UTF-8"?> 
<persistence version="1.0" 
    xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"> 
    <persistence-unit name="gnWebPU" transaction-type="RESOURCE_LOCAL"> 
     <provider>org.hibernate.ejb.HibernatePersistence</provider> 
     <properties> 
      <property name="hibernate.dialect" value="org.hibernate.dialect.SQLServerDialect" />    
      <property name="format_sql" value="true" /> 
      <property name="default-schema" value="dbo" /> 
      <property name="hibernate.ejb.interceptor" value="com.bot.gnweb.unit.AuditIntercepter" /> 
     </properties> 
    </persistence-unit> 
</persistence> 

と私のプロジェクトXMLパス enter image description here

答えて

1

答えはエラーメッセージに文字通りです:

2次キャッシュがアプリケーションで使用されていますが、hibernate.cache.region.factory_classプロパティが指定されていません。2次キャッシュを無効にするか、正しいリージョンファクトリクラス名をプロパティhibernate.cache.region.factory_classに設定してくださいたとえば、クラスパスで2番目のレベルのキャッシュ・プロバイダ、hibernate-infinispanが使用可能であることを確認してください)。

あなたはとてもあなたがここにこれについての詳細を読むことができます persistence.xml

<property name="hibernate.cache.provider_class" value="org.hibernate.cache.EhCacheProvider"/> 

に次のような行を追加

hibernate.cache.region.factory_classを設定してやりなさい

:私は入れhttps://stackoverflow.com/a/3675579/66686

+0

をし、問題はまだ同じです。私が何を失うか教えてください。 –

+0

キャッシュプロバイダはクラスパスで実装されていますか?それでもまったく同じエラーが表示されますか? –

関連する問題