为了账号安全,请及时绑定邮箱和手机立即绑定

hibernate 配置二级缓存的时候 出现没有EhCacheMessageLogger.<init>()方法的错误

hibernate 配置二级缓存的时候 出现没有EhCacheMessageLogger.<init>()方法的错误

落子鸢 2017-04-08 19:13:18
具体堆栈信息如下:java.lang.ExceptionInInitializerError at cn.luoziyuan.util.HibernateUtil.buildSessionFactory(HibernateUtil.java:21) at cn.luoziyuan.util.HibernateUtil.<clinit>(HibernateUtil.java:9) at MyTest.test1(MyTest.java:25) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50) at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47) at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17) at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57) at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288) at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268) at org.junit.runners.ParentRunner.run(ParentRunner.java:363) at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86) at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:678) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)Caused by: org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.cache.spi.RegionFactory] at org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:261) at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:225) at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:206) at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:295) at org.hibernate.cfg.Configuration.buildSettingsInternal(Configuration.java:2444) at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2440) at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1857) at cn.luoziyuan.util.HibernateUtil.buildSessionFactory(HibernateUtil.java:15) ... 25 moreCaused by: org.hibernate.HibernateException: could not instantiate RegionFactory [org.hibernate.cache.ehcache.EhCacheMessageLogger] at org.hibernate.cache.internal.RegionFactoryInitiator.initiateService(RegionFactoryInitiator.java:101) at org.hibernate.cache.internal.RegionFactoryInitiator.initiateService(RegionFactoryInitiator.java:46) at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.initiateService(StandardServiceRegistryImpl.java:105) at org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:251) ... 32 moreCaused by: java.lang.NoSuchMethodException: org.hibernate.cache.ehcache.EhCacheMessageLogger.<init>() at java.lang.Class.getConstructor0(Unknown Source) at java.lang.Class.getConstructor(Unknown Source) at org.hibernate.cache.internal.RegionFactoryInitiator.initiateService(RegionFactoryInitiator.java:97) ... 35 more下面是我导入的包的列表:这是sessionfactory的配置文件<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE hibernate-configuration PUBLIC        "-//Hibernate/Hibernate Configuration DTD 3.0//EN"        "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd"><hibernate-configuration>    <session-factory>        <property name="connection.driver_class">com.mysql.jdbc.Driver</property>        <property name="connection.url">jdbc:mysql://localhost:3306/employee</property>        <property name="connection.username">root</property>        <property name="connection.password">1029</property>        <!-- JDBC connection pool (use the built-in) -->        <property name="connection.pool_size">1</property>        <!-- SQL dialect -->        <property name="dialect">org.hibernate.dialect.MySQL5Dialect</property>        <!-- Enable Hibernate's automatic session context management -->        <property name="current_session_context_class">thread</property>               <!-- Echo all executed SQL to stdout -->        <property name="show_sql">true</property>        <property name="format_sql">true</property>        <!-- Drop and re-create the database schema on startup -->        <property name="hbm2ddl.auto">updata</property>        <property name="hibernate.cache.use_second_level_cache">true</property>        <property name="hibernate.cache.region.factory_class" >org.hibernate.cache.ehcache.EhCacheMessageLogger</property>        <mapping  resource="cn/luoziyuan/entity/Person.hbm.xml"></mapping>        <mapping resource="cn/luoziyuan/entity/Address.hbm.xml"></mapping>        <class-cache usage="read-only" class="cn.luoziyuan.entity.Person"/>                   </session-factory>   </hibernate-configuration>希望各位大神能给出解决的方案
查看完整描述

1 回答

?
落子鸢

TA贡献2条经验 获得超2个赞

通过排查基本上断定是hibernate-tools的3.3.1版本不支持新的ehcache配置方式导致的。因为在我的hibernate.cgf.xml中,使用的是<property name="hibernate.cache.region.factory_class">net.sf.ehcache.hibernate.EhCacheRegionFactory</property>来配置ehcache的,这是ehcache新的配置方式,从异常的层级关系上看,应该是hibernate-tools插件本身不支持这配制方式,改用<property name="hibernate.cache.provider_class">net.sf.ehcache.hibernate.EhCacheProvider</property>来配制后问题解决。

查看完整回答
1 反对 回复 2017-04-08
  • 1 回答
  • 0 关注
  • 2803 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信