jsr338-experts@jpa-spec.java.net

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

From: Oliver Gierke <ogierke_at_vmware.com>
Date: Thu, 17 Jan 2013 16:50:57 +0100

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
 */