gpt4 book ai didi

java - noSuchMethodError setDefaultTransactionManager - HIBERNATE 缓存

转载 作者:太空宇宙 更新时间:2023-11-04 14:14:24 27 4
gpt4 key购买 nike

我正在尝试使用 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&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>

最佳答案

在类路径中存在几个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

关于java - noSuchMethodError setDefaultTransactionManager - HIBERNATE 缓存,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27930044/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com