Hibernate version: 3.2.6, Feb 7, 2008
Hi everyone,
I got a little problem with second level caching. I'm using ehcache (v.1.4.1) as second-level-cache provider. It works with referenced entities. They are cached and actually return a match when used the second time. (e.g. Entity_A has a reference to Entity_B, when loading A, B is cached)
However, if I load an entity using session.get(<PersistentClass>, <PK>) it queries the cache (miss) but never seem to add it to the cache.
Meaning, if I do a get for the same object in a different session (same JVM) ,it's still a miss. Isn't it supposed to be added and retrieved (CacheMode = NORMAL)?
If I use
SessionFactory.getStatistics().getSecondLevelCacheStatistics("myRegion")
.getEntries();
the map is populated and actually matches occur on instances that did not match before.
Annotations:
Code:
@Entity
@org.hibernate.annotations.Entity(mutable = false)
@Table(name = "CPFields")
@Cache(usage = CacheConcurrencyStrategy.READ_ONLY, region="myRegion", include="all")
Code:
CPFields field = (CPFields) dbSession.get(CPFields.class, fieldId);
Code:
Hibernate:
select
cpfields0_.FIELDID as FIELDID6_0_,
cpfields0_.KONSTANTENFIRST as KONSTANT2_6_0_,
cpfields0_.ERPFIELD as ERPFIELD6_0_,
cpfields0_.ERPFIELDLEN as ERPFIELD4_6_0_,
cpfields0_.ERPFORMAT as ERPFORMAT6_0_,
cpfields0_.MESFIELD as MESFIELD6_0_,
cpfields0_.MESFIELDLEN as MESFIELD7_6_0_,
cpfields0_.MESFORMAT as MESFORMAT6_0_,
cpfields0_.REMARKS as REMARKS6_0_
from
CPFields cpfields0_
where
cpfields0_.FIELDID=?
ehcache.xml
Code:
<ehcache>
<diskStore path="java.io.tmpdir" />
<defaultCache maxElementsInMemory="5000" eternal="true"
overflowToDisk="true" />
<cache name="myRegion" maxElementsInMemory="15000" eternal="true"
overflowToDisk="true" />
</ehcache>
Any input is highly appreciated!
- Thanks a lot