OiO.lk Blog java making one annotation out of severals
java

making one annotation out of severals


I’m using JPA and in almost every entity class, I have the same 3 annotations for my id:

@Entity
public class Club {

    private static final String SEQ = "Club_Seq";


    @Id
    @GeneratedValue(generator=SEQ, strategy=GenerationType.SEQUENCE)
    @SequenceGenerator(name=SEQ, sequenceName=SEQ, allocationSize=1)
    protected long id;
}

what I’d really love is shortening it and make my own annotation that will be replaced by these 3. So this is what I want to write:

    @GeneratedSequence(name=SEQ)
    protected long id;

Does java allow for me to write a custom annotation that will be compiled/changed/expanded into the 3 JPA annotations? And how would I do that?



You need to sign in to view this answers

Exit mobile version