jpa-spec
  1. jpa-spec
  2. JPA_SPEC-43

Allow type level annotations to be used as meta-annotations

    Details

    • Type: Improvement Improvement
    • Status: Open
    • Priority: Major Major
    • Resolution: Unresolved
    • Affects Version/s: None
    • Fix Version/s: 2.2
    • Labels:
      None

      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.

        Issue Links

          Activity

          No work has yet been logged on this issue.

            People

            • Assignee:
              Lukas Jungmann
              Reporter:
              Oliver Gierke
            • Votes:
              5 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

              • Created:
                Updated: