我正在尝试使用hibernate缓存创建一个应用程序几个小时,但我收到错误: 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>
答案 0 :(得分:0)
在classpath中出现几个ehcache库,看看 https://forum.hibernate.org/viewtopic.php?f=1&t=1008979
第一依赖&#34; ehcache-core&#34;不是必需的,删除它。 在第二个依赖&#34; hibernate-ehcache&#34;正确的版本&#34; ehcache&#34;已经存在,请查看http://mvnrepository.com/artifact/org.hibernate/hibernate-ehcache/3.3.2.GA