[hibernate-dev] [OGM] Precedence of options specified on different levels

Gunnar Morling gunnar at hibernate.org
Tue Dec 3 04:48:50 EST 2013


Hi,

In the context of embedded associations for CouchDB [1], I'm working on
support for configuring the association storage mode using our new option
system [2]. I can see the following "axes" of configuration here:

* via annotation
  - on an association property
  - on a type
* via the option API
  - on an association property
  - on a type
  - on the global level
* via a configuration property as given via OgmConfiguration,
persistence.xml etc.
* on super-types
  - via annotations or API
  - on the property or entity level

I'm looking now for a sensible and comprehensible algorithm for taking
these sources of configuration into account and determining the effective
setting for a given association. This could be one way:

1) check API
  a) look for a setting given via the programmatic API for the given
property
  b) if the property is not configured, look for a setting given for the
entity
  c) if the entity itself is not configured, repeat a) and b) iteratively
on super-types if present
  d) if no type from the hierarchy is configured look for the global setting

2) check annotations
  if no configuration could be found in 1), do the same for annotations,
i.e.
  a) look for configuration on the given property
  b) look for configuration on the given entity
  c) repeat a) and b) iteratively on super-types if present

3) take default value given via OgmConfiguration/persistence.xml etc.

This algorithm ensures that:
* API configuration always takes precedence over annotation configuration;
e.g. if a super-type is configured via the API or the setting is given on
the API global level, any annotations are ignored
* "More local" configuration takes precedence; i.e. a type's own
configuration wins over configuration from super-types, property-level
configuration wins over entity-level configuration

Note that any setting given via OgmConfiguration/persistence.xml would be
handled as last fallback option, i.e. any configuration given via
annotations or the API would take precedence over that. I first didn't like
that but I came to think it makes sense, if the property name conveys that
semantics, e.g. "defaultAssociationStorageMode".

Any other thoughts or alternative approaches around this?

Thanks,

--Gunnar

[1] https://hibernate.atlassian.net/browse/OGM-389
[1] https://hibernate.atlassian.net/browse/OGM-208


More information about the hibernate-dev mailing list