Hibernate4.3.8配置二级缓存Unable to create requested service [org.hibernate.cache.spi.

_SK羅宾_ 2015-04-10 02:45:42
hibernate.cfg.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="connection.username">root</property>
<property name="connection.password">root</property>
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="connection.url">jdbc:mysql:///hibernate</property>

<property name="dialect">org.hibernate.dialect.MySQLDialect</property>

<property name="show_sql">true</property>
<property name="format_sql">true</property>

<property name="hbm2ddl.auto">update</property>

<!-- 配置使用session.getCurrentSession()方法 -->
<property name="current_session_context_class">thread</property>

<!-- 设置数据库隔离级别 -->
<property name="connection.isolation">2</property>

<!-- session删除对象后, 把其 OID 置为 null -->
<property name="use_identifier_rollback">true</property>

<!-- 设定 JDBC 的 Statement 读取数据的时候每次从数据库中取出的记录条数 -->
<property name="jdbc.fetch_size">100</property>

<!-- 设定对数据库进行批量删除,批量更新和批量插入的时候的批次大小 -->
<property name="jdbc.batch_size">30</property>

<!-- 配置启用 hibernate 的二级缓存 -->
<property name="cache.use_second_level_cache">true</property>

<!-- 配置hibernate二级缓存使用的产品 -->
<property name="hibernate.cache.region.factory_class">
org.hibernate.cache.egcache.EhCacheRegionFactory
</property>

<mapping resource="com/xujc/hibernate/entities/Department.hbm.xml"></mapping>
<mapping resource="com/xujc/hibernate/entities/Employee.hbm.xml"></mapping>

<!-- 配置对哪些类使用 hibernate 的二级缓存 -->
<class-cache usage="read-write" class="com.xujc.hibernate.entities.Employee"/>

</session-factory>
</hibernate-configuration>
报错信息
四月 10, 2015 2:28:07 下午 org.hibernate.annotations.common.reflection.java.JavaReflectionManager <clinit>
INFO: HCANN000001: Hibernate Commons Annotations {4.0.5.Final}
四月 10, 2015 2:28:07 下午 org.hibernate.Version logVersion
INFO: HHH000412: Hibernate Core {4.3.8.Final}
四月 10, 2015 2:28:07 下午 org.hibernate.cfg.Environment <clinit>
INFO: HHH000206: hibernate.properties not found
四月 10, 2015 2:28:07 下午 org.hibernate.cfg.Environment buildBytecodeProvider
INFO: HHH000021: Bytecode provider name : javassist
四月 10, 2015 2:28:07 下午 org.hibernate.cfg.Configuration configure
INFO: HHH000043: Configuring from resource: /hibernate.cfg.xml
四月 10, 2015 2:28:07 下午 org.hibernate.cfg.Configuration getConfigurationInputStream
INFO: HHH000040: Configuration resource: /hibernate.cfg.xml
四月 10, 2015 2:28:07 下午 org.hibernate.internal.util.xml.DTDEntityResolver resolveEntity
WARN: HHH000223: Recognized obsolete hibernate namespace http://hibernate.sourceforge.net/. Use namespace http://www.hibernate.org/dtd/ instead. Refer to Hibernate 3.6 Migration Guide!
四月 10, 2015 2:28:07 下午 org.hibernate.cfg.Configuration addResource
INFO: HHH000221: Reading mappings from resource: com/xujc/hibernate/entities/Department.hbm.xml
四月 10, 2015 2:28:07 下午 org.hibernate.internal.util.xml.DTDEntityResolver resolveEntity
WARN: HHH000223: Recognized obsolete hibernate namespace http://hibernate.sourceforge.net/. Use namespace http://www.hibernate.org/dtd/ instead. Refer to Hibernate 3.6 Migration Guide!
四月 10, 2015 2:28:07 下午 org.hibernate.cfg.Configuration addResource
INFO: HHH000221: Reading mappings from resource: com/xujc/hibernate/entities/Employee.hbm.xml
四月 10, 2015 2:28:07 下午 org.hibernate.internal.util.xml.DTDEntityResolver resolveEntity
WARN: HHH000223: Recognized obsolete hibernate namespace http://hibernate.sourceforge.net/. Use namespace http://www.hibernate.org/dtd/ instead. Refer to Hibernate 3.6 Migration Guide!
四月 10, 2015 2:28:07 下午 org.hibernate.cfg.Configuration doConfigure
INFO: HHH000041: Configured SessionFactory: null
四月 10, 2015 2:28:07 下午 org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
WARN: HHH000402: Using Hibernate built-in connection pool (not for production use!)
四月 10, 2015 2:28:07 下午 org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH000401: using driver [com.mysql.jdbc.Driver] at URL [jdbc:mysql:///hibernate]
四月 10, 2015 2:28:07 下午 org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH000046: Connection properties: {user=root, password=****}
四月 10, 2015 2:28:07 下午 org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH000006: Autocommit mode: false
四月 10, 2015 2:28:07 下午 org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH000149: JDBC isolation level: READ_COMMITTED
四月 10, 2015 2:28:07 下午 org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
INFO: HHH000115: Hibernate connection pool size: 20 (min=1)
四月 10, 2015 2:28:08 下午 org.hibernate.dialect.Dialect <init>
INFO: HHH000400: Using dialect: org.hibernate.dialect.MySQLDialect
四月 10, 2015 2:28:08 下午 org.hibernate.engine.transaction.internal.TransactionFactoryInitiator initiateService
INFO: HHH000399: Using default transaction strategy (direct JDBC transactions)
四月 10, 2015 2:28:08 下午 org.hibernate.hql.internal.ast.ASTQueryTranslatorFactory <init>
INFO: HHH000397: Using ASTQueryTranslatorFactory
Initial SessionFactory creation failed.org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.cache.spi.RegionFactory]
...全文
509 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
suciver 2015-04-10
  • 打赏
  • 举报
回复
jar包有了吗,org.hibernate.cache.egcache.EhCacheRegionFactory这个类不是hibernate的而是ehcache-core包的

67,512

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧