jsr338-experts@jpa-spec.java.net

[jsr338-experts] Re: Feature request: allow type level annotations to be used as meta-annotations

From: Oliver Gierke <ogierke_at_vmware.com>
Date: Thu, 17 Jan 2013 21:15:11 +0100

There you go: http://java.net/jira/browse/JPA_SPEC-43 :)

Am 17.01.2013 um 20:53 schrieb Linda DeMichiel <linda.demichiel_at_oracle.com>:

> Hi Oliver,
>
> I agree with your suggestion. We tried to bring in a Metatype/Stereotype-like functionality
> into Java EE 7, but ran out of runway for this release. It is definitely on our roadmap
> for Java EE 8 however. You can view the discussions on the javaee-spec.java.net project archives.
>
> Could you please log this in the JPA JIRA as an RFE for JPA.next?
>
> thanks,
>
> -Linda
>
>
> On 1/17/2013 7:50 AM, Oliver Gierke wrote:
>> Hi all,
>>
>> I repeatedly find myself annotating my JPA entities with the very same set of annotations:
>>
>> @Entity
>> @EntityListeners(AuditingEntityListener.class)
>> class Person {
>>
>> }
>>
>> If both @Entity and @EntityListener were allowed to be used as meta-annotations I could collapse them into:
>>
>> @Target(TYPE)
>> @Retention(RUNTIME)
>> @Entity
>> @EntityListeners(AuditingEntityListener.class)
>> @interface @AuditedEntity {
>>
>> }
>>
>> Resulting in:
>>
>> @AuditedEntity
>> class Person {
>>
>> }
>>
>> This is in line with the meta-annotation handling CDI exposes to introduce annotation with richer semantics in annotation code [0]. The following changes would be required.
>>
>> - Add ElementType.ANNOTATION_TYPE to the relevant annotations
>> - Specify that persistence providers have to evaluate the annotations from the meta-level as well using the first one found, so that locally defined annotations would be considered first.
>>
>> Cheers,
>> Ollie
>>
>> [0] https://github.com/dblevins/metatypes/
>>

-- 
/**
 * @author Oliver Gierke - Senior Member Technical Staff
 *
 * @param email ogierke_at_vmware.com
 * @param phone +49-351-30929001
 * @param fax   +49-351-418898439
 * @param skype einsdreizehn
 * @see http://www.olivergierke.de
 */