Hi there,
I can't seem to setup EhCache 2.10.0 properly with Hibernate 4.3.1. Have followed many tutorials but I am not getting the expected outcome.
At first I wasn't caching at all, but recently many unexpected things have arosen which pressumably point to a wrong caching setting. My problem is that in my application at certain ocassions some entities are not persisted in the database. After checking code execution and seeing nothing was wrong with the code, we checked the database, and it was fine, changes were comitted successfully. But then when loading the same object in the gui, changes aren't updated, and shows and old version of it. Seems caching problems isn't it? Bear in mind that everytime I edit an object a start and commit a new different transaction (app managed though, not JTA).
So I am trying EhCache, but am getting the same results.... something has to be wrong with it. Can anybody point any hints out?
Here are my setup files.
Code:
<?xml version="1.0" encoding="UTF-8"?>
<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="ehcache.xsd" updateCheck="true"
monitoring="autodetect" dynamicConfig="true">
<diskStore path="java.io.tmpdir/ehcache" />
<defaultCache maxEntriesLocalHeap="10000" eternal="false"
timeToIdleSeconds="5" timeToLiveSeconds="5" diskSpoolBufferSizeMB="30"
maxEntriesLocalDisk="10000000" diskExpiryThreadIntervalSeconds="120"
memoryStoreEvictionPolicy="LRU" statistics="true">
<persistence strategy="localTempSwap" />
</defaultCache>
<cache name="com.sofia.model.reports.flexreports.FlexReport" maxEntriesLocalHeap="50" eternal="false"
timeToIdleSeconds="1" timeToLiveSeconds="1">
</cache>
</ehcache>
As a start, I set very low timeToLive and timeToIdle values, to force cache deletion. I want to ensure I get the freshest data.
And persistence.xml (yes I still work with legacy files from the previous persistence provider)
Code:
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
<persistence-unit name="SofiaPU" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
...
<class>com.sofia.model.reports.flexreports.FlexReport</class>
...
<validation-mode>NONE</validation-mode>
<properties>
<property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/dbname"/>
<property name="javax.persistence.jdbc.password" value="dbpass"/>
<property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"/>
<property name="javax.persistence.jdbc.user" value="appuser"/>
<property name="hibernate.cache.provider_class" value="net.sf.ehcache.hibernate.EhCacheProvider"/>
<property name="hibernate.cache.use_second_level_cache" value="true" />
<property name="hibernate.cache.region.factory_class" value="org.hibernate.cache.ehcache.EhCacheRegionFactory" />
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/>
<property name="hibernate.connection.release_mode" value="on_close"/>
<property name="hibernate.show_sql" value="false"/>
</properties>
Regards and many thanks in advance.
Carlos Conti.