0 Replies Latest reply on Sep 20, 2006 3:54 PM by icebearoz

    Setting @Table(name=.. @Column(name=.. at runtime

    icebearoz

      Hi Together,

      I am new to EJB3 and therefore I need your help. Please forgive me if this question is not very imaginative.

      My case:
      ----------

      Let's say I have two tables with different names but with the same structure:

      Team_Green (id, first_name, last_name)
      Team_Blue (id, first_name, last_name)
      

      Now I want to use one entity bean (ejb3) for both tables. Like the following one:
      package ...
      
      import ...
      
      @Entity
      @Table(name="<table_name>")
      public class TeamMember implements Serializable {
      
       private String id;
       private String firstName;
       private String lastName;
      
       public TeamMember() {
       super();
       }
      
       public TeamMember(String id, String firstName, String lastName) {
       super();
       this.id = id;
       this.firstName = firstName;
       this.lastName = lastName
       }
      
       @Id
       @Column(name="id") // I know that this one is not necessary
       public String getId() {
       return id;
       }
       public void setId(String id) {
       this.id = id;
       }
      
       @Column(name="first_name")
       public String getFirstName() {
       return firstName;
       }
       public void setFirstName(String fristName) {
       this.firstName = firstName;
       }
      
       @Column(name="last_name")
       public String getLastName() {
       return lastName;
       }
       public void setLastName(String lastName) {
       this.lastName = lastName;
       }
      
      }
      


      My question:
      ---------------
      a:)
      How can I set the @Table(name=?...?) at runtime?

      Assuming that I know which team member belongs to which team (green or blue):
      How can I set the @Table annotation to @Table(name=?Team_Green?) - if the team member belongs to the green team - or to @Table(name=?Team_Blue?) - it the person belongs to the blue team.

      Is this in any way applicable? And if yes can someone please give me a short example, tip, hint, etc?

      b:)
      If a:) is applicable can I do such things with the annotation @Column(name=..) too?


      Thanks for your help in advance.

      Regards