Leaving aside JPA for the moment, you can in fact inherit annotations on
_classes_ where the annotation has the @Inherited meta-annotation. This
has been so since Java 1.5.
It's not used much: I stand to be corrected but I think no annotations
in the "java" package and only 3 annotations in "javax", in base JDK
1.6, use the @Inherited meta-annotation. One such is
javax.xml.ws.ServiceMode, so if a JAX-WS 2.0 provider class happens to
use the @ServiceMode annotation, any class that extends that provider
class will also have it.
JSR-250 has very little to say about this meta-annotation and I believe
mentions it only once, in the discussion of @Resource. The general
thrust of JSR 250 (see Section 2.1 "General Guidelines for Inheritance
of Annotations") is to acknowledge, as you guys have pointed out, that
individual specifications have decided how to treat annotation
inheritance. Although it's worth pointing out that JSR 250 does provide
recommendations in this regard.
I'm not so sure but that the JSR 250 authors don't implicitly deprecate
the use of @Inherited, although I don't see that they ever flat out say so.
In any case @Inherited is somewhat dangerous. One hopes that it is
*always* accompanied by the @Documented meta-annotation, so that at
least on the originally annotated class users can see that it is there,
and if things start to misbehave they can follow the Javadoc link and
see that that annotation is in fact inherited. I've seen posts where
people did run into problems because they had no idea that an annotation
was @Inherited; Javadoc (AFAIK) does not follow annotation inheritance
and display the inherited annotation information on children. One might
have to subclass the standard Javadoc doclet to get that, I dunno.
It's a bit worse than that because @Inherited affects the complete depth
of inheritance. It will apply to children of children of children...
In any case, I agree with both of you when it comes to @MappedSuperclass:
1) Since it does not have the @Inherited meta-annotation you do have to
declare it on every class that needs it (according to Java language
annotation rules);
2) Point #1 is semi-irrelevant because each framework, JSR 250 be
damned, can do whatever it wants to;
3) Even if @MappedSuperclass did have the @Inherited meta-annotation,
*or* JPA implementations analyzed it in the same effective way, you (the
OP) still wouldn't want to do what you want apparently to do. JPA
provides a *lot* of mechanisms foe helping people out when there is a
serious mismatch between their RDBMS table setup and their object
hierarchy, but it also works best when you've got a 1:1 mapping between
tables and simple JPA entities. No problem with a single depth use of
@MappedSuperclass [1], but I wouldn't take it any further than that.
AHS
1. Fairly common to use @MappedSuperclass simply because a lot of
implementations have generic fields that relate to every entity/table
for auditing, for example. Although DBs audit too this data is not
always as accessible to an application.
--
...wherever the people are well informed they can be trusted with their
own government...
-- Thomas Jefferson, 1789