Hibernate uses two different caches for objects. The first level cache, and the second level cache.
The first level cache is associated with the Session object, while the second level cache is associated with the hibernate SessionFactory object.
Currently, the cartridge architecture creates one Session instance from the SessionFactory instance for each method that is called at the EJB's services. This means that caching will only occur if a method accesses the same instance more than once. This can be improved by activating the second level cache features provided by Hibernate.
To achieve this task, the cartridge includes support for generating the Hibernate descriptor files will all the possible cache settings included in the hibernate specification.
Additionally, each second level cache manager usually needs its own descriptor file with cache settings specific to this manager. The cartridge provides a template for creating the EhCache Manager descriptor file. For other managers, this template could be overwritten to generate another manager descriptor file.
Currently AndroMDA fully supports
EhCache
to provide the second level cache features to
the cartridge. When enabled, the cartridge will create caches on queries, the Hibernate descriptor
files, and the EhCache.xml
file with the specific configuration.
The cache settings provide support for customizing the cache configuration. The namespace properties for the cache settings are as following:
net.sf.hibernate.cache.EhCacheProvider
net.sf.hibernate.cache.StandardQueryCacheFactory
Currently the cartridge only includes the dependencies for working with EhCache
To enable cache features on generated files, the following namespace properties should be used.
hibernate.cache.use_query_cache
will be set to true
.
The cartridge provides a default namespace property for each entity cache settings configuration. These properties will be applied by default (that is, if there is no specific tagged value on the entity that overrides the value). Namespace properties for entities are:
read-write
, other possible values are
nonstrict-read-write
and
read-only
Namespace properties and tagged values are available to customize EhCache Configuration . Namespace properties for EhCache configuration are:
Associations caching configuration can be configured individually. The namespace default property can be overridden using the tagged value. Namespace property for EhCache configuration is:
read-write
, other possible values are
nonstrict-read-write
and
read-only
The cartridge provides default namespace properties for activating the cache on one query.
When enabled the generated code will contain an additional
query.setCacheable(true)
line.
The namespace property for finder methods is:
read-write
, other possible values are
nonstrict-read-write
and
read-only