Configuration and testing of Hibernate3 level two cache

Source: Internet
Author: User

1. Configure Ehcache.xml files and place them under classpath:

<?xml version="1.0" encoding="GBK"?>
   <ehcache>
       <diskStore path="D:\\TempObject"/>
       <defaultCache
            maxElementsInMemory="10000"
            eternal="false"
            timeToIdleSeconds="100"
            timeToLiveSeconds="1000"
           overflowToDisk="true"
       />
       <cache name="com.sitechasia.occ.core.base.ExampleForTest" maxElementsInMemory="10000"
           eternal="false"
           timeToIdleSeconds="100"
           timeToLiveSeconds="1000"
           overflowToDisk="true"
        />
  </ehcache>

It is recommended that the cache name and the classpath name be the same when customizing cache.

(1) Do not use the default caching policy Defaultcache (multiple class shares)

(2) Do not give cache name another name

Otherwise inherit abstracttransactionaldatasourcespringcontexttests to do the test when thrown

Org.hibernate.cache.CacheException:java.lang.IllegalStateException:The Com.sitechasia.occ.core.base.ExampleForTest cache is not alive. (I commented on the red cache, using Defaultcache causes)

2. Add in ExampleForTest.hbm.xml: (if there is a collection, you also need to add)

  <class name="com.sitechasia.occ.core.base.ExampleForTest"
    table="TESTTABLE" lazy="false">
    <cache usage="read-write"/>
    <id name="id" type="java.lang.String">
      <column name="id" length="32" />
      <generator class="uuid"></generator>
    </id>
    <property name="field1" type="java.lang.String" />
    <property name="field2" type="java.lang.String" />
  </class>

If Annocation is used, the class is added before the

@Cache (usage = cacheconcurrencystrategy.read_write)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.