jakartaee / jakartaee/persistence
Allow type level annotations to be used as meta-annotations
- Dominant language
- Java
- Stars
- 267
- Forks
- 78
- Avg merge
- 1d 6h
- Merged PRs (30d)
- 13
Description
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. 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.
Contributor guide
Assessment
This issue has not been assessed yet.