jakartaee / jakartaee/persistence

Allow type level annotations to be used as meta-annotations

Open
#43 18 comments 7 reactions 1 assignee Claimed by @lukasj View on GitHub
candidate-for-4 JavaEE metatypes Priority: Major Type: Improvement
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

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.