spring中配置hibernate3.X 二级缓存
来源:互联网 发布:手机淘宝的客服在哪里 编辑:程序博客网 时间:2024/05/16 04:52
前提:导入ehcache-1.2.3.jar包
1.在ApplicationContext.xml中添加粗体部分
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.OracleDialect</prop>
<prop key="hibernate.hbm2ddl.auto">update</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.cache.use_second_level_cache"></prop>
<prop key="hibernate.cache.provider_class">org.hibernate.cache.EhCacheProvider</prop>
<prop key="hibernate.generate_statistics">true</prop>
</props>
</property>
2.将ehcache.xml拷贝到src下,如果没有的朋友可以来这里下载
http://download.csdn.net/detail/ahuangtaoa/4950698 免费的
3.配置cache策略(也就是告诉ehcache二级缓存的是那些对象,比如我的是Employee对象),在Employee对应的Employee.hbm.xml中添加
<cache usage="read-write"/> 一定要在<class>标签内 <id>标签前,tld约束,你懂的
4.测试:代码
private static void textEhcache() {
ApplicationContext ac = new ClassPathXmlApplicationContext("applicationContext.xml");
SessionFactory factory = (SessionFactory) ac.getBean("sessionFactory");
Session session = null;
Transaction tx = null;
try {
session = factory.openSession();
tx = session.beginTransaction();
Employee emp = (Employee) session.get(Employee.class, 10);
System.out.println(emp.getId() + " " + emp.getName());
tx.commit();
} catch (Exception e) {
if (tx != null) {
tx.rollback();
tx = null;
}
e.printStackTrace();
} finally {
if (session != null && session.isOpen()) {
session.close();
session = null;
}
}
System.out.println("**************");
try {
session = factory.openSession();
tx = session.beginTransaction();
Employee emp = (Employee) session.get(Employee.class, 10);
System.out.println(emp.getId() + " " + emp.getName());
tx.commit();
} catch (Exception e) {
if (tx != null) {
tx.rollback();
tx = null;
}
e.printStackTrace();
} finally {
if (session != null && session.isOpen()) {
session.close();
session = null;
}
}
// 完成一个统计,统计命中率
System.out.println(factory.getStatistics());
}
- spring中配置hibernate3.X 二级缓存
- spring学习笔记16--Spring2.x+Hibernate3.x +Struts1.x整合开发(4)-----Hibernate3.x配置二级缓存
- spring中配置二级缓存
- spring中配置二级缓存
- spring中配置二级缓存
- hibernate3.X二级缓存的使用
- hibernate3.X二级缓存的使用
- hibernate3.X二级缓存的使用
- hibernate3.X二级缓存的使用
- spring中配置hibernate二级缓存
- spring中配置hibernate二级缓存
- spring中配置hibernate二级缓存
- spring中配置hibernate二级缓存
- spring中配置hibernate二级缓存
- spring中配置hibernate二级缓存
- Hibernate3.6二级缓存配置 - ehcache
- Hibernate3 二级缓存的使用配置细节
- Hibernate3 二级缓存的使用配置细节
- getWriter() has already been called for this response 的解决办法
- Sql Server起今为止最全的【日期函数大全】!(超经典,全部为示例)
- 微软面试题系列:求子数组最大和
- 父母该如何辅导孩子做作业
- JAVA的字符串拼接与性能
- spring中配置hibernate3.X 二级缓存
- 第一个多线程程序+对象和句柄的区别+感悟
- 网络实名制
- 对2012年的总结
- HDU-1166(树状数组写法)
- 关于firefox(火狐浏览器)document.all和document.layers .
- 从头再来
- 3.2web功能
- IOS 6 基础框架概览