hibernateTemplate 2nd level cache
Caching queries with HibernateTemplate
hibernateTemplate caching
Speed Up Your Hibernate Applications with Second-Level Caching
hibernate jboss cache guide
Hibernate Caching with JBOSS Treecache example
Hibernate Caching
=============================================================
=============================================================
The treecache.xml
<?xml version="1.0" encoding="UTF-8"?>
<server>
<mbean code="org.jboss.cache.TreeCache" name="jboss.cache:service=TreeCache">
<depends>jboss:service=TransactionManager</depends>
<!-- Configure the TransactionManager -->
<attribute name="TransactionManagerLookupClass">org.jboss.cache.JBossTransactionManagerLookup</attribute>
<!-- Isolation level : SERIALIZABLE
REPEATABLE_READ (default)
READ_COMMITTED
READ_UNCOMMITTED
NONE
-->
<attribute name="IsolationLevel">REPEATABLE_READ</attribute>
<!-- Valid modes are LOCAL, REPL_ASYNC and REPL_SYNC -->
<attribute name="CacheMode">LOCAL</attribute>
<!-- Just used for async repl: use a replication queue -->
<attribute name="UseReplQueue">false</attribute>
<!-- Replication interval for replication queue (in ms) -->
<attribute name="ReplQueueInterval">0</attribute>
<!-- Max number of elements which trigger replication -->
<attribute name="ReplQueueMaxElements">0</attribute>
<!-- Whether or not to fetch state on joining a cluster -->
<attribute name="FetchStateOnStartup">true</attribute>
<!-- The max amount of time (in milliseconds) we wait until the
initial state (ie. the contents of the cache) are retrieved from
existing members in a clustered environment
-->
<attribute name="InitialStateRetrievalTimeout">5000</attribute>
<!-- Number of milliseconds to wait until all responses for a synchronous call have been received. -->
<attribute name="SyncReplTimeout">15000</attribute>
<!-- Max number of milliseconds to wait for a lock acquisition -->
<attribute name="LockAcquisitionTimeout">15000</attribute>
<!-- Name of the eviction policy class. -->
<!--
<attribute name="EvictionPolicyClass">org.jboss.cache.eviction.FIFOPolicy</attribute>
-->
<!-- Specific eviction policy configurations. This is LRU -->
<attribute name="EvictionPolicyConfig">
<config>
<attribute name="wakeUpIntervalSeconds">5</attribute>
<region name="/_default_">
<attribute name="maxNodes">5000</attribute>
<attribute name="timeToLiveSeconds">1000</attribute>
<attribute name="maxAgeSeconds">120</attribute>
</region>
<region name="hibernate/HibernateLogEntryDao">
<attribute name="maxNodes">5000</attribute>
<attribute name="timeToLiveSeconds">1000</attribute>
</region>
</config>
</attribute>
</mbean>
</server>
=================================================
The treecache.xml,to be placed in the common location where log4j properties files are read
Jar's Needed Jboss-cache.jar and jgroups.jar and comman hibernate Jar's
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:util="http://www.springframework.org/schema/util"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:jboss="http://www.springmodules.org/schema/jboss"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
http://www.springmodules.org/schema/jboss
http://www.springmodules.org/schema/cache/springmodules-jboss.xsd">
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">
<property name="driverClassName"><value>oracle.jdbc.driver.OracleDriver</value></property>
<property name="url"><value>jdbc:oracle:thin:@localhost:1521:XE</value></property>
<property name="username"><value>smc</value></property>
<property name="password"><value>smc</value></property>
<property name="maxActive"><value>100</value></property>
<property name="maxIdle"><value>30</value></property>
<property name="maxWait"><value>1000</value></property>
<property name="defaultAutoCommit"><value>false</value></property>
</bean>
<bean id="hibernateSessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="mappingLocations">
<list>
<value>classpath*:/dataaccess/hibernate/*.hbm.xml</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.cache.use_second_level_cache">true</prop>
<prop key="hibernate.cache.use_query_cache">true</prop>
<prop key="hibernate.cache.provider_class">org.hibernate.cache.TreeCacheProvider</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.dialect">org.hibernate.dialect.Oracle9Dialect</prop>
<prop key="hibernate.current_session_context_class">thread</prop>
<prop key="hibernate.transaction.factory_class">org.hibernate.transaction.JDBCTransactionFactory</prop>
</props>
</property>
</bean>
<bean id="hibernateDaoSupport" abstract="true" class="org.springframework.orm.hibernate3.support.HibernateDaoSupport">
<property name="sessionFactory" ref="hibernateSessionFactory"/>
</bean>
<bean id="templatelessLogEntryDao" class="com.apress.prospring2.ch11.dataaccess.hibernate.TemplatelessHibernateInvoiceLogEntryDao">
<constructor-arg ref="hibernateSessionFactory"/>
</bean>
<bean class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor"/>
<bean id="lodDao" class="com.apress.prospring2.ch11.dataaccess.HiberNateDaoSupportIml">
<property name="sessionFactory" ref="hibernateSessionFactory"/>
</bean>
</beans>
Implementation Code:-
public List<LogEntry> getAll() {
System.out.println("GetAll Called");
long start, end, total;
start = System.currentTimeMillis();
getHibernateTemplate().setQueryCacheRegion("HibernateLogEntryDao");
getHibernateTemplate().setCacheQueries(true);
List<LogEntry> returns=getHibernateTemplate().find("from LogEntry");
end = System.currentTimeMillis();
total = end - start;
System.out.println("Totall-->>"+total);
return returns;
}
hibernateTemplate 2nd level cache
Caching queries with HibernateTemplate
hibernateTemplate caching
Speed Up Your Hibernate Applications with Second-Level Caching
hibernate jboss cache guide
Using treecache as 2nd level cache
JBoss Cache based Hibernate Second Level Cache provider
Once I set caching for one query in one method of my DAO using "getHibernateTemplate().setCacheQueries(true);", then it is caching queries from all methods. Is there any solution to cache only queries for selected method
ReplyDeleteInteresting Article
ReplyDeleteEJB 3 Online Training | Java Online Training
Java Online Training from India | Core Java Online Training
Have you been thinking about the power sources and the tiles whom use blocks I wanted to thank you for this great read!! I definitely enjoyed every little bit of it and I have you bookmarked to check out the new stuff you post
ReplyDeleteData Science course in Indira nagar
Data Science course in marathahalli
Data Science Interview questions and answers
Data science training in tambaram
Data Science course in btm layout
Data science course in kalyan nagar
This is an awesome blog. Really very informative and creative contents.
ReplyDeleteaws Training in Bangalore
python Training in Bangalore
hadoop Training in Bangalore
angular js Training in Bangalore
bigdata analytics Training in Bangalore
python Training in Bangalore
aws Training in Bangalore
Great post..Its very useful for me to understand the information..Keep on blogging..
ReplyDeleteaws Training in Bangalore
python Training in Bangalore
hadoop Training in Bangalore
angular js Training in Bangalore
bigdata analytics Training in Bangalore
python Training in Bangalore
aws Training in Bangalore
This comment has been removed by the author.
ReplyDeleteNice Blog.The Blog is really Informative every concept shpuld be very neatly Arranged.
ReplyDeleteData Science Training Course In Chennai | Data Science Training Course In Anna Nagar | Data Science Training Course In OMR | Data Science Training Course In Porur | Data Science Training Course In Tambaram | Data Science Training Course In Velachery
kralbet
ReplyDeletebetpark
tipobet
slot siteleri
kibris bahis siteleri
poker siteleri
bonus veren siteler
mobil ödeme bahis
betmatik
NAHBST
شركة مكافحة القوارض
ReplyDeleteشركة تنظيف شقق
gfjhhtkjhytkjuyikuk
ReplyDeleteشركة صيانة افران
شركة تنظيف بالاحساء YRQlAJChAL
ReplyDeleteصيانة افران مكة PSd3V5AiCC
ReplyDeleteGreat explanation of using HibernateTemplate with second-level caching! The detailed steps and code examples make it easy to implement. This guide is super helpful for improving application performance.
ReplyDeletecyber security internship for freshers | cyber security internship in chennai | ethical hacking internship | cloud computing internship | aws internship | ccna course in chennai | java internship online
شركة مكافحة حشرات ابوظبي 6UuEOjGCYZ
ReplyDeleteشركة عزل اسطح بوادي الدواسر 66UN9QFXeM
ReplyDelete