- 浏览: 459617 次
- 性别:
- 来自: 陕西.西安
文章分类
最新评论
-
gaodadawei:
登录失败,请重试楼主,我目前遇到这样一个错误,claros i ...
James+Claros+intouch2.1配置 -
VerRan:
qq346448412 写道请问。你上一节、 用的ORACLE ...
James+Claros+intouch2.1配置 -
qq346448412:
请问。你上一节、 用的ORACLE数据库、 这一节又用的是MY ...
James+Claros+intouch2.1配置 -
paladin1988:
good,我喜欢..
Hibernate自关联关系 -
lygxy12:
请问,能给163发邮件吗?该怎么配置?我安装上面的操作,发给1 ...
James+Claros+intouch2.1配置
Hibernate二级缓存
1. HIbernate.cfg.xml文件
2. ehcache.xml
3. 测试代码
4. 结果
1. 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"> <!-- Generated by MyEclipse Hibernate Tools. --> <hibernate-configuration> <session-factory> <property name="dialect"> org.hibernate.dialect.Oracle9Dialect </property> <property name="show_sql">true</property> <property name="connection.url"> </property> <property name="connection.username"></property> <property name="connection.password"></property> <property name="connection.driver_class"> oracle.jdbc.driver.OracleDriver </property> <property name="myeclipse.connection.profile">Oralce</property> <property name="hibernate.query.factory_class"> org.hibernate.hql.classic.ClassicQueryTranslatorFactory </property> <!-- 添加缓存拆建的接口实现类 --> <property name="cache.provider_class">org.hibernate.cache.EhCacheProvider</property> <!-- 设置应用查询缓存 --> <property name="hibernate.cache.use_query_cache">true</property> <mapping resource="com/lht/po/VerranCust.hbm.xml" /> <mapping resource="com/lht/po/VerranOrder.hbm.xml" /> </session-factory> </hibernate-configuration>
2. ehcache.xml
<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="ehcache.xsd"> <diskStore path="C:\\cache"/> <!-- 配置全局监听器 --> <cacheManagerEventListenerFactory class="com.lht.ehcache.listener.EcacheListenerFactory"/> <defaultCache maxElementsInMemory="10000" eternal="false" timeToIdleSeconds="120" timeToLiveSeconds="120" overflowToDisk="true" diskPersistent="false" diskExpiryThreadIntervalSeconds="120" memoryStoreEvictionPolicy="LRU" /> <cache name="com.lht.po.VerranCust" maxElementsInMemory="300" eternal="true" overflowToDisk="false" /> <cache name="com.lht.po.VerranOrder" maxElementsInMemory="300" eternal="true" overflowToDisk="false" /> <cache name="Test" maxElementsInMemory="10000" eternal="false" overflowToDisk="true" timeToIdleSeconds="2" timeToLiveSeconds="600" memoryStoreEvictionPolicy="LRU"> <!-- 配置特定缓存的监听器 --> <cacheEventListenerFactory class="com.lht.ehcache.listener.EcacheSingleListenerFactory"> </cacheEventListenerFactory> </cache> <!-- 设置默认的查询缓存的数据过期策略 --> <cache name="org.hibernate.cache.StandardQueryCache" maxElementsInMemory="50" eternal="false" timeToIdleSeconds="3600" timeToLiveSeconds="7200" overflowToDisk="true" /> <!-- 设置时间戳缓存的数据过期策略 --> <cache name="org.hibernate.cache.UpdateTimestampsCache" maxElementsInMemory="5000" eternal="true" overflowToDisk="true" /> <!-- 设置自定义命名查询缓存customerQueries的数据过期策略 --> <cache name="myCacheRegion" maxElementsInMemory="1000" eternal="false" timeToIdleSeconds="300" timeToLiveSeconds="600" overflowToDisk="true" /> </ehcache>
3. 测试代码
public static void main(String[] args) { // TODO Auto-generated method stub HibernateTest test=new HibernateTest(); for (int i=0;i<10;i++){ System.out.println("第"+(i+1)+"次"); TestTimer timer = new TestTimer("testGetCountries"); test.testFind(); timer.done(); } }
4. 结果
log4j:WARN [g:stdout.log] should be System.out or System.err. log4j:WARN Using previously set target, System.out by default. 10:31:34,625 DEBUG BaseDAO:29 - 开始创建session 10:31:34,781 INFO HibernateSession:37 - sessionfactory is null 开始创建---- 10:31:36,046 DEBUG CacheManager:239 - Configuring ehcache from classpath. 10:31:36,046 DEBUG ConfigurationFactory:122 - Configuring ehcache from ehcache.xml found in the classpath: file:/C:/Documents%20and%20Settings/cattsoft/%e6%a1%8c%e9%9d%a2/BSS/CacheStudy/bin/ehcache.xml 10:31:36,046 DEBUG ConfigurationFactory:87 - Configuring ehcache from URL: file:/C:/Documents%20and%20Settings/cattsoft/%e6%a1%8c%e9%9d%a2/BSS/CacheStudy/bin/ehcache.xml 10:31:36,046 DEBUG ConfigurationFactory:139 - Configuring ehcache from InputStream 10:31:36,062 DEBUG BeanHandler:213 - Ignoring ehcache attribute xmlns:xsi 10:31:36,062 DEBUG BeanHandler:213 - Ignoring ehcache attribute xsi:noNamespaceSchemaLocation 10:31:36,062 DEBUG DiskStoreConfiguration:65 - Disk Store Path: C:\\cache 10:31:36,093 DEBUG PropertyUtil:86 - propertiesString is null. 10:31:36,093 INFO EcacheListenerFactory:18 - ecache 监听工厂 10:31:36,093 DEBUG ConfigurationHelper:183 - No CachePeerListenerFactoryConfiguration specified. Not configuring a CacheManagerPeerListener. 10:31:36,093 DEBUG ConfigurationHelper:159 - No CachePeerProviderFactoryConfiguration specified. Not configuring a CacheManagerPeerProvider. 10:31:36,218 DEBUG ConfigurationHelper:135 - No BootstrapCacheLoaderFactory class specified. Skipping... 10:31:36,218 DEBUG ConfigurationHelper:135 - No BootstrapCacheLoaderFactory class specified. Skipping... 10:31:36,218 DEBUG ConfigurationHelper:135 - No BootstrapCacheLoaderFactory class specified. Skipping... 10:31:36,218 DEBUG ConfigurationHelper:135 - No BootstrapCacheLoaderFactory class specified. Skipping... 10:31:36,218 DEBUG PropertyUtil:86 - propertiesString is null. 10:31:36,218 INFO EcacheSingleListenerFactory:16 - 监听单element 10:31:36,218 DEBUG ConfigurationHelper:135 - No BootstrapCacheLoaderFactory class specified. Skipping... 10:31:36,218 DEBUG ConfigurationHelper:135 - No BootstrapCacheLoaderFactory class specified. Skipping... 10:31:36,218 DEBUG ConfigurationHelper:135 - No BootstrapCacheLoaderFactory class specified. Skipping... 10:31:36,234 DEBUG DiskStore:182 - Deleting data file org.hibernate.cache.UpdateTimestampsCache.data 10:31:36,250 DEBUG MemoryStore:73 - Initialized net.sf.ehcache.store.LruMemoryStore for org.hibernate.cache.UpdateTimestampsCache 10:31:36,250 DEBUG LruMemoryStore:71 - org.hibernate.cache.UpdateTimestampsCache Cache: Using SpoolingLinkedHashMap implementation 10:31:36,250 DEBUG Cache:429 - Initialised cache: org.hibernate.cache.UpdateTimestampsCache 10:31:36,250 INFO EcacheListener:35 - start adding=============缓存名称为=org.hibernate.cache.UpdateTimestampsCache 10:31:36,250 DEBUG DiskStore:182 - Deleting data file Test.data 10:31:36,250 DEBUG MemoryStore:73 - Initialized net.sf.ehcache.store.LruMemoryStore for Test 10:31:36,250 DEBUG LruMemoryStore:71 - Test Cache: Using SpoolingLinkedHashMap implementation 10:31:36,265 DEBUG Cache:429 - Initialised cache: Test 10:31:36,265 INFO EcacheListener:35 - start adding=============缓存名称为=Test 10:31:36,265 DEBUG DiskStore:182 - Deleting data file org.hibernate.cache.StandardQueryCache.data 10:31:36,265 DEBUG MemoryStore:73 - Initialized net.sf.ehcache.store.LruMemoryStore for org.hibernate.cache.StandardQueryCache 10:31:36,265 DEBUG LruMemoryStore:71 - org.hibernate.cache.StandardQueryCache Cache: Using SpoolingLinkedHashMap implementation 10:31:36,265 DEBUG Cache:429 - Initialised cache: org.hibernate.cache.StandardQueryCache 10:31:36,265 INFO EcacheListener:35 - start adding=============缓存名称为=org.hibernate.cache.StandardQueryCache 10:31:36,265 DEBUG MemoryStore:73 - Initialized net.sf.ehcache.store.LruMemoryStore for com.lht.po.VerranOrder 10:31:36,265 DEBUG LruMemoryStore:71 - com.lht.po.VerranOrder Cache: Using SpoolingLinkedHashMap implementation 10:31:36,265 DEBUG Cache:429 - Initialised cache: com.lht.po.VerranOrder 10:31:36,265 INFO EcacheListener:35 - start adding=============缓存名称为=com.lht.po.VerranOrder 10:31:36,265 DEBUG MemoryStore:73 - Initialized net.sf.ehcache.store.LruMemoryStore for com.lht.po.VerranCust 10:31:36,265 DEBUG LruMemoryStore:71 - com.lht.po.VerranCust Cache: Using SpoolingLinkedHashMap implementation 10:31:36,265 DEBUG Cache:429 - Initialised cache: com.lht.po.VerranCust 10:31:36,265 INFO EcacheListener:35 - start adding=============缓存名称为=com.lht.po.VerranCust 10:31:36,265 DEBUG DiskStore:182 - Deleting data file myCacheRegion.data 10:31:36,265 DEBUG MemoryStore:73 - Initialized net.sf.ehcache.store.LruMemoryStore for myCacheRegion 10:31:36,265 DEBUG LruMemoryStore:71 - myCacheRegion Cache: Using SpoolingLinkedHashMap implementation 10:31:36,265 DEBUG Cache:429 - Initialised cache: myCacheRegion 10:31:36,265 INFO EcacheListener:35 - start adding=============缓存名称为=myCacheRegion 10:31:36,625 DEBUG DiskStore:182 - Deleting data file com.lht.po.VerranCust.verRanOrders.data 10:31:36,625 DEBUG MemoryStore:73 - Initialized net.sf.ehcache.store.LruMemoryStore for com.lht.po.VerranCust.verRanOrders 10:31:36,625 DEBUG LruMemoryStore:71 - com.lht.po.VerranCust.verRanOrders Cache: Using SpoolingLinkedHashMap implementation 10:31:36,625 DEBUG Cache:429 - Initialised cache: com.lht.po.VerranCust.verRanOrders 10:31:36,625 INFO EcacheListener:35 - start adding=============缓存名称为=com.lht.po.VerranCust.verRanOrders 10:31:36,765 INFO HibernateSession:40 - sessionfactory 创建完毕---- 10:31:36,765 DEBUG BaseDAO:32 - session打开成功 第1次 Hibernate: select verrancust0_.CUST_ID as col_0_0_ from LUCITEST.VERRAN_CUST verrancust0_ where (verrancust0_.CUST_ID=? ) 10:31:37,093 DEBUG MemoryStore:138 - com.lht.po.VerranCustCache: com.lht.po.VerranCustMemoryStore miss for com.lht.po.VerranCust#1000 10:31:37,093 DEBUG Cache:661 - com.lht.po.VerranCust cache - Miss Hibernate: select verrancust0_.CUST_ID as CUST1_0_0_, verrancust0_.NAME as NAME0_0_, verrancust0_.STS as STS0_0_ from LUCITEST.VERRAN_CUST verrancust0_ where verrancust0_.CUST_ID=? 10:31:37,140 INFO HibernateTest:71 - VerRan 10:31:37,140 DEBUG MemoryStore:138 - com.lht.po.VerranCust.verRanOrdersCache: com.lht.po.VerranCust.verRanOrdersMemoryStore miss for com.lht.po.VerranCust.verRanOrders#1000 10:31:37,140 DEBUG Cache:661 - com.lht.po.VerranCust.verRanOrders cache - Miss Hibernate: select verranorde0_.ORDER_CUST_ID as ORDER4_1_, verranorde0_.ORDER_ID as ORDER1_1_, verranorde0_.ORDER_ID as ORDER1_1_0_, verranorde0_.ORDER_PRICE as ORDER2_1_0_, verranorde0_.ORDER_NAME as ORDER3_1_0_, verranorde0_.ORDER_CUST_ID as ORDER4_1_0_ from LUCITEST.VERRAN_ORDER verranorde0_ where verranorde0_.ORDER_CUST_ID=? 10:31:37,156 INFO HibernateTest:76 - bb testGetCountries : 391 ms. 第2次 Hibernate: select verrancust0_.CUST_ID as col_0_0_ from LUCITEST.VERRAN_CUST verrancust0_ where (verrancust0_.CUST_ID=? ) 10:31:37,156 INFO HibernateTest:71 - VerRan 10:31:37,156 INFO HibernateTest:76 - bb testGetCountries : 0 ms. 第3次 Hibernate: select verrancust0_.CUST_ID as col_0_0_ from LUCITEST.VERRAN_CUST verrancust0_ where (verrancust0_.CUST_ID=? ) 10:31:37,171 INFO HibernateTest:71 - VerRan 10:31:37,171 INFO HibernateTest:76 - bb testGetCountries : 15 ms. 第4次 Hibernate: select verrancust0_.CUST_ID as col_0_0_ from LUCITEST.VERRAN_CUST verrancust0_ where (verrancust0_.CUST_ID=? ) 10:31:37,171 INFO HibernateTest:71 - VerRan 10:31:37,171 INFO HibernateTest:76 - bb testGetCountries : 0 ms. 第5次 Hibernate: select verrancust0_.CUST_ID as col_0_0_ from LUCITEST.VERRAN_CUST verrancust0_ where (verrancust0_.CUST_ID=? ) 10:31:37,171 INFO HibernateTest:71 - VerRan 10:31:37,171 INFO HibernateTest:76 - bb testGetCountries : 0 ms. 第6次 Hibernate: select verrancust0_.CUST_ID as col_0_0_ from LUCITEST.VERRAN_CUST verrancust0_ where (verrancust0_.CUST_ID=? ) 10:31:37,187 INFO HibernateTest:71 - VerRan 10:31:37,187 INFO HibernateTest:76 - bb testGetCountries : 16 ms. 第7次 Hibernate: select verrancust0_.CUST_ID as col_0_0_ from LUCITEST.VERRAN_CUST verrancust0_ where (verrancust0_.CUST_ID=? ) 10:31:37,187 INFO HibernateTest:71 - VerRan 10:31:37,187 INFO HibernateTest:76 - bb testGetCountries : 0 ms. 第8次 Hibernate: select verrancust0_.CUST_ID as col_0_0_ from LUCITEST.VERRAN_CUST verrancust0_ where (verrancust0_.CUST_ID=? ) 10:31:37,187 INFO HibernateTest:71 - VerRan 10:31:37,187 INFO HibernateTest:76 - bb testGetCountries : 0 ms. 第9次 Hibernate: select verrancust0_.CUST_ID as col_0_0_ from LUCITEST.VERRAN_CUST verrancust0_ where (verrancust0_.CUST_ID=? ) 10:31:37,203 INFO HibernateTest:71 - VerRan 10:31:37,203 INFO HibernateTest:76 - bb testGetCountries : 16 ms. 第10次 Hibernate: select verrancust0_.CUST_ID as col_0_0_ from LUCITEST.VERRAN_CUST verrancust0_ where (verrancust0_.CUST_ID=? ) 10:31:37,203 INFO HibernateTest:71 - VerRan 10:31:37,203 INFO HibernateTest:76 - bb testGetCountries : 0 ms.
发表评论
-
springboot学习 - hello world
2017-03-15 18:15 494引子: 开始之前允许我介绍下我认识的spr ... -
Ext显示乱码问题
2012-04-03 13:27 1150转自:http://blog.csdn.net/raren/a ... -
Hadoop学习资料
2011-10-21 10:20 845http://www.cnblogs.com/wayne101 ... -
NodeJs和 mongodb初识
2011-10-20 14:41 1051NodeJS: 提供javascirpt 实现服务器端功能的引 ... -
WebService 非阻塞模式
2011-03-30 16:05 1681package com.datastruct.sort; ... -
利用 Java dump 进行 JVM 故障诊断
2011-01-11 15:58 1449转自:http://jimmyleeee.blog.163.c ... -
LocalTransactionContainment 期间回滚了一个或多个本地事务资源。
2011-01-09 10:29 1964此问题查过很多,但是大家解决方法不一。下面列出 YuLiMin ... -
RETE 算法的描述(转)
2010-07-20 16:57 1280转自:http://www.cnblogs.com/ipoin ... -
Hermes配置
2010-02-02 18:09 1125一直报错UnmarshalException 后来发现 ... -
界面原型设计工具–Balsamiq Mockups
2009-12-09 13:31 1764原文地址:http://www.pbdigg.net/s ... -
JTA 事务使用
2009-11-23 15:20 1555业务场景: 客户下发订单后,订单到竣工需要走三个岗位1,2, ... -
webSphere 下消息驱动Bean 与队列JNDI的关联
2009-09-21 17:44 14611. 消息驱动Bean配置ejb-jar.xml ... -
webService-小记
2008-03-24 18:57 1036A web service has one or more p ... -
Hessian
2008-02-16 11:16 1519Hessian is a simple binary pro ... -
利用反射机制动态将XML信息设置入对象
2007-12-05 14:23 2279引言:XML和J2EE密切的程度是不用说的了,由于我们的接口程 ... -
Action – JSP – Javascript之间的参数传递
2007-11-19 19:04 3633Action – JSP – Javascript之间的参数传 ... -
java 获取存储过程 输出参数
2007-11-13 15:21 5235connection = session.c ... -
js获得<table>的单元格信息
2007-11-08 16:41 54471. 获取表格中的某个单元格的内容 var tid= ... -
Eclipse快捷键
2007-10-23 10:47 913作用域 功能 快捷键 全 ... -
HTTP深入浅出
2007-09-27 10:10 1362转自:http://www.blogjava.ne ...
相关推荐
Hibernate二级缓存是一种提高应用程序性能的技术,它将数据存储在SessionFactory级别的缓存中,使得数据可以在不同的Session之间共享。这与一级缓存(Session级别)不同,一级缓存仅存在于单个Session生命周期内,当...
Hibernate 二级缓存是针对SessionFactory级别的全局缓存,与一级缓存(Session级别)不同,一级缓存只在单个Session生命周期内有效。二级缓存则允许不同Session之间共享数据,提高了数据访问效率,减少了对数据库的...
Hibernate 二级缓存是一种高效的数据存储机制,它能够显著提升Web应用的性能,尤其是在处理大量数据流动时。缓存的主要目标是减少应用与数据库之间的交互次数,从而降低延迟并减轻数据库服务器的压力。在Hibernate...
在这个"hibernate二级缓存实例"中,我们将深入探讨二级缓存的原理、配置以及在实际项目中的应用。 首先,我们需要了解一级缓存和二级缓存的区别。一级缓存是Session级别的,每个Session都有自己的一级缓存,用于...
**hibernate二级缓存详解** Hibernate作为Java领域中广泛使用的对象关系映射(ORM)框架,极大地简化了数据库操作。然而,在处理大量数据时,性能优化显得尤为重要,这就是二级缓存的作用。本文将深入探讨Hibernate...
**Hibernate 二级缓存总结整理** 在Java的持久化框架中,Hibernate是一个广泛使用的ORM(对象关系映射)工具,它极大地简化了数据库操作。在处理大数据量或高并发的场景下,为了提高性能和减少数据库负载,...
Hibernate二级缓存是Java开发中使用Hibernate框架进行数据持久化时优化性能的一种重要技术。它在一级缓存(Session级别的缓存)的基础上,提供了一个全局的、跨会话的数据存储层,可以显著减少对数据库的访问,从而...
二级缓存是 Hibernate 缓存策略的一部分,它在应用程序的多个会话之间共享数据,进一步优化了数据库访问效率。 二级缓存分为以下关键知识点: 1. **一级缓存与二级缓存的区别**: - 一级缓存:每个 Hibernate ...
本篇文章将深入探讨Hibernate二级缓存的概念、工作原理以及如何在实际项目中设置和使用。 **一、二级缓存概念** 一级缓存是每个Hibernate Session内部的一个内存区域,用于存储Session期间的操作对象。当Session...
本篇将详细介绍Hibernate二级缓存的概念、作用以及所需jar包的作用。 一、Hibernate二级缓存概念 Hibernate的一级缓存是指Session级别的缓存,每个Session内部都有一个一级缓存,用于存储实体对象,当Session关闭时...
本篇文章将深入探讨Hibernate的二级缓存机制,以及如何进行一级缓存与二级缓存的同步,同时还会介绍二级缓存的配置文件设置。 一级缓存是Hibernate默认提供的缓存,每个SessionFactory实例都有一个一级缓存。当对象...