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
    • 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.

        Activity

          People

          • Assignee:
            ldemichiel
            Reporter:
            Oliver Gierke
          • Votes:
            3 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated: