Example & Tutorial understanding programming in easy ways.

What are the various Catching strategies in Hibernate?

Catching strategies in Hibernate: When we work with the Hibernate web application then we will face so many problem in its performance due to database traffic. So that if we found the heavy database traffic. For the heavy database traffic we have to some technique to maintain the performance. One of the technique is that with we can solve the problem that is Hibernate.


Caching Strategies:


1) Read-only: 


1. Useful for data that is read frequently but never updated.

2. It is Simple .

3. Best performer among the all.

4. Advantage if this one is, It is safe for using in a cluster. Here is an example for using the read-only cache strategy.


<class name='abc.mutable ' mutable='true '>

<cache usage='read-only'/>

....

</class>


2) Read-Write:


1. Used when our data needs to be updated.

2. It’s having more overhead than read-only caches.

3. When Session.close() or Session.disconnect() is called the transaction should be completed in an environment where JTA is no used.

4. It is never used if serializable transaction isolation level is required.

5. In a JTA environment, for obtaining the JTA TransactionManager we must specify the property hibernate.transaction.manager_lookup_class.

6. To use it in a cluster the cache implementation must support locking.

7. Here is an example for using the read-write cache stringategy.


<class name='abc.xyz' .... >

<cache usage='read-write'/>

<set name='yuv' ... >

<cache usage='read-write'/>

</set>

</class>


3) Nonstrict read-write:


1. Needed if the application needs to update data rarely.

2. we must specify hibernate.transaction.manager_lookup_class to use this in a JTA environment .

3. The transaction is completed when Session.close() or Session.disconnect() is called In other environments (except JTA) .

4. Here is an example for using the nonstrict read-write cache stringategy.


<class name='abc.xyz' .... >

<cache usage=' nonstringict-read-write'/> 

</class>


4) Transactional:


1. It supports only transactional cache providers such as JBoss TreeCache.

2. only used in JTA environment.

Read More →