How it works

When saving a Java bean object, the bean is first transformed into an element-property tree using the Java reflection API.

For the following class fragment the property x is created if T is a primitive type (e.g String, Enum, Double, double, Integer, int, Long, long, XMLGregrorianCalendar, GregrorianCalendar, Boolean, boolean) or a List of it otherwise the element reference x is created.

  class C {

    public T getX()


This tree object is then compared to the corresponding persisted tree, if one exists. It is inserted as a new entity if the primary key property is null otherwise the modified values are marked and the revision counter is increased.

On a retrieve operation the bean is restored from the persisted element tree.

The object id is mapped to the element id if requested. The same applies to the version id which is used for optimistic locking.

For more information see also the Wikipedia articles:


To improve the performance of retrieve operations Ehcache is used. It is configured as shown below:

  <diskStore path="" />

  <cache name="ch.semafor.gendas.service.PersistenceCache"
        overflowToDisk="true" />

  • diskStore Sets the path to the directory where cache .data files are created.
  • maxElementsInMemory Sets the maximum number of objects that will be created in memory eternal
  • eternal If true, timeouts are ignored and the element is never expired
  • overflowToDisk cache elements can overflow to disk when the in-memory cache has reached the maxInMemory limit
  • timeToLiveSeconds - Sets the time to live for an element before it expires. i.e. The maximum time between creation time and when an element expires. Only used if eternal is false.

For furher information please refer to the Ehcache dcoumentation