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 EhCacheto 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.xmlfile with the specific configuration.
The cache settings provide support for customizing the cache configuration. The namespace properties for the cache settings are as following:
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.
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:
This property can be overridden using the following tagged value:
Namespace properties and tagged values are available to customize EhCache Configuration. Namespace properties for EhCache configuration are:
The corresponding tagged values to overwrite the default values 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:
Tagged value:
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:
This default value will be used for all the queries that are not overridden using the tagged value: