2015-01-13 51 views
1

我試圖與休眠緩存應用了好幾個小時,但我得到的錯誤: 的NoSuchMethodError setDefaultTransactionManager的NoSuchMethodError setDefaultTransactionManager - 休眠CACHING

其我的第一個Hibernate應用程序中,我將是你非常感激幫幫我。

緩存我的Maven依賴:

<dependency> 
    <groupId>net.sf.ehcache</groupId> 
    <artifactId>ehcache-core</artifactId> 
    <version>2.3.1</version> 
</dependency> 
<dependency> 
    <groupId>org.hibernate</groupId> 
    <artifactId>hibernate-ehcache</artifactId> 
    <version>3.3.2.GA</version> 
</dependency> 

的hibernate.cfg.xml

<?xml version="1.0" encoding="utf-8"?> 
<!DOCTYPE hibernate-configuration SYSTEM 
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd"> 

<hibernate-configuration> 
    <session-factory> 
     <property name="hibernate.dialect"> 
      org.hibernate.dialect.MySQLDialect 
     </property> 
     <property name="hibernate.connection.driver_class"> 
      com.mysql.jdbc.Driver 
     </property> 

     <!-- Assume test is the database name --> 
     <property name="hibernate.connection.url"> 
      jdbc:mysql://localhost:3036/test?autoReconnect=true&amp;useUnicode=true&amp;characterEncoding=UTF-8 
     </property> 
     <property name="hibernate.connection.username"> 
      root 
     </property> 


     <property name="current_session_context_class">org.hibernate.context.ManagedSessionContext</property> 
     <property name="hibernate.cache.use_second_level_cache">true</property> 
     <property name="hibernate.cache.use_query_cache">true</property> 
     <property name="hibernate.cache.region.factory_class">net.sf.ehcache.hibernate.EhCacheRegionFactory</property> 

     <property name="hbm2ddl.auto">update</property> 
     <property name="hibernate.bytecode.use_reflection_optimizer">false</property> 
     <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property> 
     <property name="show_sql">true</property> 
     <mapping class="info.talacha.filmweb.models.Movie" /> 
     <mapping class="info.talacha.filmweb.models.Person" /> 
     <mapping class="movies.Cinema" /> 
     <mapping class="movies.Timetable" /> 
     <mapping class="movies.PopularMovie" /> 
    </session-factory> 
</hibernate-configuration> 

,我希望緩存每個類是與高速緩存註釋:

@Entity 
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE) 
@Table(name = "people") 
public class Person implements Serializable{ 
} 

的Ehcache .xml

<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:noNamespaceSchemaLocation="http://ehcache.org/ehcache.xsd" 
    maxBytesLocalHeap ="900"> 

<defaultCache 
    eternal="false" 
    timeToIdleSeconds="300" 
    timeToLiveSeconds="1200" 
    overflowToDisk="false"> 
    </defaultCache> 
</ehcache> 

回答