Search code examples
javaspringannotations

How to make a parent interface who has some annotations from children using Spring?


I have a lot of model classes who has same annotations like that:

Child:

@Entity
@DynamicUpdate
@Table(name = "STATUS")
@Data
@EqualsAndHashCode(onlyExplicitlyIncluded = true, doNotUseGetters = 
true)
public class Child{...}

Parent:

public @interface Parent
{...}

I want to set annotations in parent. So child implements in one simple annotation @Parent

And how to pass the parameters from Child To Parent?


Solution

  • You can just pass the annotations to the Parent annotation:

    @Entity
    @DynamicUpdate
    @Table(name = "STATUS")
    @Data
    @EqualsAndHashCode(onlyExplicitlyIncluded = true, doNotUseGetters = true)
    public @interface Parent {
    }
    

    And use it in you Child class:

    @Parent
    public class Child {
    }