打开cache后query的list和iterator方法区别
1、ehcache.xml文件
<?xml version="1.0" encoding="UTF-8"?> <ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../config/ehcache.xsd"> <!-- Subdirectories can be specified below the property e.g. java.io.tmpdir/one --> <diskStore path="java.io.tmpdir"/> <!-- Mandatory Default Cache configuration. These settings will be applied to caches created programmtically using CacheManager.add(String cacheName) --> <defaultCache maxElementsInMemory="10000" eternal="false" timeToIdleSeconds="120" timeToLiveSeconds="120" overflowToDisk="true" maxElementsOnDisk="10000000" diskPersistent="false" diskExpiryThreadIntervalSeconds="120" memoryStoreEvictionPolicy="LRU" /> <cache name="org.hibernate.cache.spi.UpdateTimestampsCache" maxElementsInMemory="5000" eternal="true" overflowToDisk="true" /> <cache name="org.hibernate.cache.internal.StandardQueryCache" maxElementsInMemory="10000" eternal="false" timeToLiveSeconds="120" overflowToDisk="true" /> </ehcache>
2、applicationContext.xml配置sessionFactory
<bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean"> <property name="dataSource"> <ref bean="dataSource" /> </property> <property name="hibernateProperties"> <props> <prop key="hibernate.dialect"> org.hibernate.dialect.MySQLDialect </prop> <!-- 是否打印sql --> <prop key="hibernate.show_sql">true</prop> <!-- 格式化sql <prop key="hibernate.format_sql">true</prop> --> <!-- 配置二级缓存 --> <prop key="hibernate.cache.use_second_level_cache">true</prop> <prop key="hibernate.cache.region.factory_class">org.hibernate.cache.EhCacheRegionFactory</prop> <prop key="hibernate.net.sf.ehcache.configurationResourceName">ehcache.xml</prop> <!-- 开启查询时的二级缓存 --> <prop key="hibernate.cache.use_query_cache">true</prop> </props> </property> <property name="mappingResources"> <list> <value>com/db/entity/User.hbm.xml</value> </list> </property> </bean>
测试案例:
hibernate中Query的list和iterator区别(续)
原文:http://www.cnblogs.com/SaraMoring/p/5656732.html