2017-03-01 18 views
0

私はehcacheを使い慣れています。私は以下の設定を使用しています。私はehcacheを3に設定すると、私のプロジェクトは良いコンパイルが、私は、エンドポイントにクエリを送信するとき、私はエラーました:ehcacheを使用しているときのエラー

2017-03-01 11:46:02,032 ERROR org.springframework.transaction.interceptor.TransactionInterceptor : Application exception overridden by rollback error 
java.lang.AbstractMethodError: org.hibernate.cache.ehcache.internal.regions.EhcacheTimestampsRegion.put(Lorg/hibernate/engine/spi/SessionImplementor;Ljava/lang/Object;Ljava/lang/Object;)V 
    at org.hibernate.cache.spi.UpdateTimestampsCache.preInvalidate(UpdateTimestampsCache.java:95) 
    at org.hibernate.engine.spi.ActionQueue.invalidateSpaces(ActionQueue.java:618) 
    at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:584) 
    at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:434) 
    at org.hibernate.event.internal.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:337) 
    at org.hibernate.event.internal.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:39) 
    at org.hibernate.internal.SessionImpl.flush(SessionImpl.java:1295) 

application.gradle

buildscript { 
    ext { 
     springBootVersion = '1.3.5.RELEASE' 
    } 
    repositories { 
     mavenCentral() 
    } 
    dependencies { 
     classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}") 
    } 
} 

apply plugin: 'java' 
apply plugin: 'eclipse-wtp' 
apply plugin: 'spring-boot' 
apply plugin: 'war' 


war { 
    baseName = 'deliverypoint' 
    version = '0.0.1-SNAPSHOT' 
} 
sourceCompatibility = 1.8 
targetCompatibility = 1.8 

repositories { 
    mavenCentral() 
} 

configurations { 
    providedRuntime 
} 

ext { 
    jodaTimeVersion = '2.9.4' 
} 

dependencies { 
    compile('org.springframework.boot:spring-boot-starter') 
    compile('org.springframework.boot:spring-boot-starter-data-jpa') 
    compile('org.springframework.boot:spring-boot-starter-jersey') 
    compile('org.springframework.boot:spring-boot-starter-web') 
    compile('org.apache.tomcat.embed:tomcat-embed-jasper') 
    compile('org.postgresql:postgresql') 
    providedRuntime('org.springframework.boot:spring-boot-starter-tomcat') 
    testCompile('org.springframework.boot:spring-boot-starter-test') 
    compile("joda-time:joda-time:$jodaTimeVersion") 
    compile("org.apache.tomcat:tomcat-dbcp:7.0.55") 
    compile group: 'org.jadira.usertype', name: 'usertype.jodatime', version: '2.0.1' 
    compile group: 'org.hibernate', name: 'hibernate-core', version: '5.1.0.Final' 
    compile group: 'org.hibernate', name: 'hibernate-entitymanager', version: '5.1.0.Final' 
    compile group: 'org.hibernate', name: 'hibernate-validator', version: '5.2.4.Final' 
    compile(group: 'org.apache.tiles', name: 'tiles-jsp', version: '3.0.5') 

    compile('org.springframework.security:spring-security-taglibs') 

    providedRuntime('javax.servlet:jstl') 


    compile("org.springframework.boot:spring-boot-starter-security") 
    compile("org.springframework.security.oauth:spring-security-oauth2") 
    compile group: 'org.springframework.social', name: 'spring-social-core', version: '1.1.4.RELEASE' 
    compile group: 'org.springframework.social', name: 'spring-social-security', version: '1.1.4.RELEASE' 

    compile group: 'org.modelmapper.extensions', name: 'modelmapper-spring', version: '0.7.7' 

    // https://mvnrepository.com/artifact/com.google.maps/google-maps-services 
    compile group: 'com.google.maps', name: 'google-maps-services', version: '0.1.16' 

// compile (group: 'org.hibernate', name: 'hibernate-ehcache', version: '5.2.1.Final') { 
//  exclude group: 'net.sf.ehcache', module: 'ehcache' //by both name and group 
// } 
// 
// compile group: 'org.ehcache', name: 'ehcache', version: '3.3.0' 


    compile group: 'net.sf.ehcache', name: 'ehcache-core', version: '2.6.11' 
    compile group: 'org.hibernate', name: 'hibernate-ehcache', version: '5.2.1.Final' 
    compile group: 'org.springframework', name: 'spring-context-support', version: '4.1.4.RELEASE' 
    // compile('org.springframework.boot:spring-boot-starter-cache') 
} 

bootRun { 
    systemProperties System.properties 
} 

コンフィグ休止:

import org.hibernate.SessionFactory; 
import org.hibernate.cfg.AvailableSettings; 
import org.springframework.beans.factory.annotation.Autowired; 
import org.springframework.context.ApplicationContext; 
import org.springframework.context.annotation.Bean; 
import org.springframework.context.annotation.Configuration; 
import org.springframework.core.env.Environment; 
import org.springframework.orm.hibernate5.HibernateTemplate; 
import org.springframework.orm.hibernate5.HibernateTransactionManager; 
import org.springframework.orm.hibernate5.LocalSessionFactoryBean; 

import javax.sql.DataSource; 
import java.util.Map; 
import java.util.Properties; 
@Configuration 
    public class DatabaseConfig { 

     @Autowired 
     private Environment env; 

     @Autowired 
     private ApplicationContext applicationContext; 

     @Bean 
     public Map<String, DataSource> dataSourceMap() { 
      return applicationContext.getBeansOfType(DataSource.class); 
     } 

     /** 
     * init startup resources like sql scripts 
     * 
     * @return DataSourceInitializer 
     */ 

     @Bean 
     public HibernateTransactionManager transactionManager(SessionFactory sessionFactory) { 
      HibernateTransactionManager hibernateTransactionManager = new HibernateTransactionManager(sessionFactory); 
      hibernateTransactionManager.setAutodetectDataSource(false); 
      return hibernateTransactionManager; 
     } 

     @Bean 
     public HibernateTemplate hibernateTemplateMain(SessionFactory sessionFactory) { 
      return new HibernateTemplate(sessionFactory); 
     } 

     public Properties hibernateProperties() { 
      return new Properties() { 
       { 
        setProperty("hibernate.hbm2ddl.auto", env.getProperty("datasources.ddl-auto")); 
        setProperty("hibernate.dialect", env.getProperty("datasources.hibernate.dialect")); 
        setProperty("hibernate.show_sql", env.getProperty("datasources.show-sql")); 
        setProperty("hibernate.format_sql", env.getProperty("datasources.format-sql")); 
        setProperty("hibernate.multiTenancy", env.getProperty("datasources.multiTenancyStrategy")); 
        setProperty("hibernate.multi_tenant_connection_provider", env.getProperty("datasources.multiTenancyConnectionProvider")); 
        setProperty("hibernate.tenant_identifier_resolver", env.getProperty("datasources.multiTenancyIdentifierResolver")); 
        setProperty("hibernate.default_schema", env.getProperty("datasources.default_schema")); 
        setProperty(AvailableSettings.USE_GET_GENERATED_KEYS, "true"); 

        setProperty(AvailableSettings.USE_SECOND_LEVEL_CACHE, "true"); 
        setProperty(AvailableSettings.USE_QUERY_CACHE, "true"); 
        setProperty(AvailableSettings.CACHE_REGION_FACTORY, "org.hibernate.cache.ehcache.SingletonEhCacheRegionFactory"); 
        setProperty("net.sf.ehcache.configurationResourceName","/ehcache.xml"); 
       } 
      }; 
     } 

     @Bean 
     public LocalSessionFactoryBean sessionFactoryMain(Map<String, DataSource> dataSourceMap) { 
      DataSource dataSource = dataSourceMap.get("datasourcemain"); 
      LocalSessionFactoryBean sessionFactory = new LocalSessionFactoryBean(); 
      sessionFactory.setDataSource(dataSource); 
      sessionFactory.setPackagesToScan("io.default.deliverypoints"); 
      sessionFactory.setHibernateProperties(hibernateProperties()); 
      return sessionFactory; 
     }   
    } 

ehcache.xml

<?xml version="1.0" encoding="UTF-8"?> 
<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
     xsi:noNamespaceSchemaLocation="ehcache.xsd" updateCheck="true" 
     monitoring="autodetect" dynamicConfig="true" shared="true"> 

    <diskStore path="java.io.tmpdir/ehcache" /> 

    <defaultCache maxEntriesLocalHeap="5000" eternal="true" 
        timeToIdleSeconds="120" timeToLiveSeconds="120" diskSpoolBufferSizeMB="30" 
        maxEntriesLocalDisk="10000000" diskExpiryThreadIntervalSeconds="120" 
        memoryStoreEvictionPolicy="LRU" statistics="true"> 
     <persistence strategy="localTempSwap" /> 
    </defaultCache> 

    <cache name="billCache" maxEntriesLocalHeap="10000" 
      eternal="true" timeToIdleSeconds="0" timeToLiveSeconds="0"> 
     <persistence strategy="localTempSwap" /> 
    </cache> 

    <cache name="org.hibernate.cache.internal.StandardQueryCache" 
      maxEntriesLocalHeap="5000" eternal="false" timeToLiveSeconds="120"> 
     <persistence strategy="localTempSwap" /> 
    </cache> 

    <cache name="org.hibernate.cache.spi.UpdateTimestampsCache" 
      maxEntriesLocalHeap="5000" eternal="true"> 
     <persistence strategy="localTempSwap" /> 
    </cache> 
</ehcache> 

メインスプリングブートアプリケーションでは、@EnableCachingを使用します。私は、エンティティで使用 そして注釈:

@SuppressWarnings("serial") 
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE, region="billCache") 
@Cacheable 

答えて

0

あなたは休止状態とにehcache間のプロバイダーを配線する必要があるので、あなたは、抽象メソッドの例外を取得しています。

これを行う方法はdocumentation hereです。要するに

は、休止状態のプロパティのためのあなたのconfigセクションも含まれている必要があります答えを

  setProperty("hibernate.cache.provider_class", "org.hibernate.cache.EhCacheProvider"); 
+0

おかげで、これは私の問題( –

+0

修正この問題は固定されていないが、今は別の問題があります:組織を。 glassfish.jersey.server.ContainerException:java.lang.AbstractMethodError:org.hibernate.cache.ehcache.internal.nonstop.NonstopAwareEntityRegionAccessStrategy.get(Lorg/hibernate/engine/spi/SessionImplementor; Ljava/lang/Object; J)Ljava/lang/Object; –

+0

もう一度、接続する必要のあるものがないか、このすべてのメタデータとして使用されている注釈が正しく適用されていないためです。 その質問を見るためには、参照のためにエンティティクラスの少なくとも1つが必要になるでしょう。 – lscoughlin

関連する問題