On Mon 2013-12-16 11:06, Gunnar Morling wrote:
2013/12/13 Emmanuel Bernard <emmanuel(a)hibernate.org>
> So currently in the pull request, we now have the following
>
> 1. property > entity > global
> 2. for each level in 1., programmatic API beats annotation
>
> These are simple rules to understand and all it good.
>
> Now Gunnar tried to handle class inheritance, ie superclasses and
> overridden methods.
> And we do differ in what we consider the natural rules (or what it
> should be).
>
> Here is how I think the rules should be:
>
> 1. property > entity > global
> 2. for each level in 1., subclass > superclass and overridden method >
> parent method
> 3. for each level (in 1 and 2), programmatic API beats annotation
>
> Here is how Gunnar thinks the rules should be:
>
> 1. metadata on a class > metadata on a superclass (whether it is on a
> property or the class)
> 2. for each hierarchy level, property > entity > global
> 3. for each level in 1 and 2, programmatic API beats annotation
>
> In more concrete words,
>
> @Option(1)
> class A {
> @Option(2)
> public String getMe() {return null;}
> }
>
> @Option(3)
> class B extends A {
> @Override
> public String getMe() {return null;}
> }
>
> In my world, B.getMe has Options(2).
> In Gunnar's world, B.getMe() has @Option(3).
>
Thanks for the clear explanation and example for the issue.
> To me, a property level is always more specific than an entity, hence my
> interpretation. If someone has set a value on a given property, it would
> be dangerous to be "globally" overridden by a subclass.
>
> Thoughts?
>
What would be "dangerous" in this case?
Someone has clearly decided that A.getMe should behave in a specific way
and differently than A.getOtherMe. Overriding that via B for all of A's
properties is wrong IMO. Besides, why doesn't it override the settings
for properties that are not overridden?
I think for the author of B it's helpful to be able to change the defaults
for the entire class. Also for a reader of B its simpler to grasp the
applying configuration with my proposal, because the entire "truth" about
the annotation config can be found in B, you don't have to look into any
super-classes. So to me, that's more along the lines of the principle of
least surprise.
If you consider that the truth should be in the most specific entity, I think
you should also consider that inheriting the settings from the
superclass is against that principle and that inheritance should not be
involved.
Emmanuel