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

Gunnar Morling gunnar at hibernate.org
Wed Dec 4 12:12:03 EST 2013


2013/12/4 Emmanuel Bernard <emmanuel at hibernate.org>

> On Wed 2013-12-04 10:33, Gunnar Morling wrote:
> > 2013/12/3 Emmanuel Bernard <emmanuel at hibernate.org>
> >
> > > On Tue 2013-12-03 17:48, Gunnar Morling wrote:
> > > > Thanks, Davide.
> > > >
> > > > 2013/12/3 Davide D'Alto <davide at hibernate.org>
> > > >
> > > > > It looks good to me.
> > > > >
> > > >
> > > > Ok.
> > > >
> > > > > I first didn't like that but I came to think it makes sense, if the
> > > > > property name conveys that semantics, e.g.
> > > "defaultAssociationStorageMode".
> > > > >
> > > > > I don't think it's necessary to use the prefix "default". For me
> it is
> > > > > just a setting that it is overridden by something else in some
> > > situations,
> > > > > the same as an annotation is declared at the same time on the class
> > > and on
> > > > > an attribute.
> > > > >
> > > >
> > > > >From what I can say it's reasonable for a user to expect that
> properties
> > > > given via persistence.xml or similar actually do apply and are not
> > > > overridden by code or annotations.
> > > >
> > > > Take the MongoDB "host" as example, here we have an internal constant
> > > with
> > > > a default but the user can set "hibernate.ogm.mongodb.host" and this
> > > > setting applies. That's different from the proposed algorithm where
> the
> > > > property really would only be used as fallback if not configuration
> is
> > > > given by means of annotations or API.
> > > >
> > > > Thus I think it makes sense to make this semantics transparent via
> the
> > > > "default..." prefix in the property name.
> > >
> > > Realize guys that we have a sparse matrix model. Not all settings will
> > > be applicable globally AND per entity AND per property.
> > > host for example, probably should not have a entity/property level.
> >
> >
> > Yes, sure.
> >
> >
> > > We
> > > might want to allow for it to be set programmatically globally but in
> > > that case, I'd argue that the program should have priority over the
> XML.
> > >
> >
> > Why would you argue that way?
> >
> > IMO one needs to distinguish two different categories of properties here.
> > API > XML makes sense for properties where the XML property defines a
> > default in case no value is given via other means; hence the suggested
> > "default..." prefix. Association storage is an example; there are no
> > associations to be stored on the global level per-se, instead giving the
> > value via XML or globally acts as fallback in case no value is specified
> > for a given association.
> >
> > But there is another category of properties where the value from XML,
> > hibernate.properties etc. ultimately should be applied. The host falls
> into
> > this category. Often such setting is configured by someone executing
> > deployments, e.g. by providing a properties file within the environment,
> > rather than by a developer. So one can take one and the same artifact,
> > deploy it in different environments and have it work with different
> > database hosts.
> >
> > I'd even argue that setting the host via the API is not really useful for
> > that reason. But if it is possible to set this value via the API, the
> > XML/properties value should take precedence IMO.
>
> I do disagree.
> First off, I am not certain host should be an option. It could just
> remain a property.
>

That's what I'm saying, likely it doesn't make sense to make this an option
settable via the API.


> But assuming we want an API way to define host, I think it should have
> priority over properties. That way, I can write a piece of code that
> takes the host value from somewhere and apply it. This piece of code can
> even read that value from persistence.xml if it wants to.
> Why would you have a programmatically defined host just to have it be
> erased by the static xml/properties file?
>

I had a case in mind where a developer sets some fallback value to make the
app usable also without the properties file being present, but a deployer
could provide that file and then override the fallback values.

In your approach that would be doable by checking for presence of the value
in the properties file and only if not present setting the default value.
So I guess that's fine.


>
> Emmanuel
>


More information about the hibernate-dev mailing list