您的位置:首页 > 其它

hibernate 3.3 配置 oscache 二级缓存

2015-05-25 00:37 357 查看
hibernate 3.3 配置 oscache 二级缓存

缺少引用包错误
1.Exception in thread "main" java.lang.NoClassDefFoundError: org/slf4j/impl/StaticLoggerBinder
出现原因:hibernate 3.3.2 的 slf4j-api-1.5.8.jar 包中并没有加入 org.slf4j.impl.StaticLoggerBinder 包
解决方法:下载slf4j-1.5.8.zip,找到 slf4j-log4j12-1.5.8.jar 包导入自己的项目 
下载地址:http://www.slf4j.org/dist/slf4j-1.5.8.zip 

2.Exception in thread "main" java.lang.ExceptionInInitializerError at test.QueryTwoLevelCache.main(QueryTwoLevelCache.java:18)
Caused by: org.hibernate.HibernateException: could not instantiate RegionFactory [org.hibernate.cache.impl.bridge.RegionFactoryCacheProviderBridge]
出现原因:hibernate 3.3.2 的 oscache-2.1.jar 包中并没有导入 commons-logging.jar 包
解决方法:在oscache官方重新下载一个 oscache 找到 commons-logging.jar 包导入自己的项目

hibernate配置oscache 文件 hibernate.hbm.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.driver_class">org.gjt.mm.mysql.Driver</property>
<property name="connection.url">jdbc:mysql://localhost/my_hibernate</property>
<property name="connection.username">root</property>
<property name="connection.password">123456</property>
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="show_sql">true</property>
<property name="format_sql">false</property>

<property name="cache.use_second_level_cache">true</property>
<property name="cache.provider_class">org.hibernate.cache.OSCacheProvider</property> 
<property name="hibernate.cache.provider_configuration_file_resource_path">ehcache.xml
</property>
<property name="hibernate.generate_statistics">true</property>
<mapping resource="domain/Student.hbm.xml"/>
<class-cache usage="read-write" class="domain.Student"/>
</session-factory>
</hibernate-configuration>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: