[jboss-user] [EJB 3.0] - Setting @Table(name=.. @Column(name=.. at runtime

IceBearOZ do-not-reply at jboss.com
Wed Sep 20 15:54:52 EDT 2006


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

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3973064#3973064

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3973064



More information about the jboss-user mailing list