【发布时间】:2015-01-13 19:30:53
【问题描述】:
我正在尝试使用休眠缓存创建应用程序几个小时,但出现错误: noSuchMethodError setDefaultTransactionManager
这是我的第一个 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&useUnicode=true&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>
我要缓存的每个类都带有 Cache 注释:
@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>
【问题讨论】:
标签: java spring hibernate maven caching