【问题标题】:noSuchMethodError setDefaultTransactionManager - HIBERNATE CACHINGnoSuchMethodError setDefaultTransactionManager - 休眠缓存
【发布时间】: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&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>

我要缓存的每个类都带有 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


    【解决方案1】:

    在类路径中存在几个 ehcache 库,看 https://forum.hibernate.org/viewtopic.php?f=1&t=1008979

    第一个依赖“ehcache-core”不是必需的,删除它。 在第二个依赖项“hibernate-ehcache”中已经存在正确版本的“ehcache”,请查看http://mvnrepository.com/artifact/org.hibernate/hibernate-ehcache/3.3.2.GA

    【讨论】:

      猜你喜欢
      • 2017-08-13
      • 2010-10-27
      • 1970-01-01
      • 1970-01-01
      • 2016-08-13
      • 2012-04-29
      • 2015-01-05
      • 2011-11-18
      • 2017-01-16
      相关资源
      最近更新 更多