0 Replies Latest reply on Apr 4, 2010 9:59 PM by 843793

    Automatically Add JPA Annotations


      I am not sure if my question is annotation specific, maybe it is more generally about generating source code.... here is what I want to do:

      I want to use JPA annotations to declare the O/R mapping of my domain classes, but actually I don't want to write these annotations manually. I want to generate them automatically based on name patterns.

      e.g. I have the following class:
      public class Permission  {
          private Integer permissionID;
          private Set <AccountGroup> accountGroups = new HashSet<AccountGroup>();
      ... now I want to write a java program that adds annotations based on name patterns and get something like:
          @Column( name = "permissionID", updatable = false, nullable = false )
          @GeneratedValue(strategy = GenerationType.IDENTITY)
          private Integer permissionID;
          @ManyToMany (
              targetEntity = AccountGroup.class
          @JoinTable (
              name = "Permission_AccountGroup",
              joinColumns = @JoinColumn (name="permissionID"),
              inverseJoinColumns = @JoinColumn (name="accountGroupID")
          private Set <AccountGroup> accountGroups = new HashSet<AccountGroup>();
      What is the easiest way to insert the annotations into the source code? ... I am thinking about methods like "addAnnotationToClass / Field" ... any idea?