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)