| Author |
EJB Question. Add a new column to Many-to-many relation generated table.
|
Mayuri Roi
Greenhorn
Joined: Oct 12, 2004
Posts: 23
|
|
I have a question in EJB. Please help. Here is the scenario: 1. Websphere 6, Rational Application Developer 6, DB2 UDB 8.2 & CMP. 2. I have two beans 'Person' and 'Account' with many-to-many relationship. 3. I have two tables 'Person' and 'Account' with id as primary key in both tables. 3. Based on the many-to-many relationship of Person and Account Beans, Persons_Accounts table has been generated with two columns persons_id and accounts_id where primary key is (persons_id, accounts_id). persons_id is a foreign key to pk(id) of 'Person' and accounts_id is a foreign key to pk(id) of Account table. Till here, I dont have any problem. I am able to set Accounts to a person using person.setAccounts(accountCollection) etc. Everything is working fine and our application is in production state. But now, we have a new requirement where we need to add a new column to Persons_Accounts table. How do I do this? For ex: I need to add a flag column to this table based on which I'll have to deal with some business logic. My problem is I dont have any bean that is directly mapped to Persons_Accounts table as it got generated based on many-to-many relation. So, how do I manipulate the new column using any bean?
|
Thanks.<br />Mayuri
|
 |
Sabarish Sasidharan
Ranch Hand
Joined: Aug 29, 2002
Posts: 73
|
|
Originally posted by Mayuri Roi: I have a question in EJB. Please help. Here is the scenario: 1. Websphere 6, Rational Application Developer 6, DB2 UDB 8.2 & CMP. 2. I have two beans 'Person' and 'Account' with many-to-many relationship. 3. I have two tables 'Person' and 'Account' with id as primary key in both tables. 3. Based on the many-to-many relationship of Person and Account Beans, Persons_Accounts table has been generated with two columns persons_id and accounts_id where primary key is (persons_id, accounts_id). persons_id is a foreign key to pk(id) of 'Person' and accounts_id is a foreign key to pk(id) of Account table. Till here, I dont have any problem. I am able to set Accounts to a person using person.setAccounts(accountCollection) etc. Everything is working fine and our application is in production state. But now, we have a new requirement where we need to add a new column to Persons_Accounts table. How do I do this? For ex: I need to add a flag column to this table based on which I'll have to deal with some business logic. My problem is I dont have any bean that is directly mapped to Persons_Accounts table as it got generated based on many-to-many relation. So, how do I manipulate the new column using any bean?
This is based on what i have read in books... So take it with a pinch of salt... Many to many relationships with additional columns in the relationship table cannot be mapped using Many to many relationship in WSAD. The relationship table will have to be treated as a domain object and should have its own bean with many to one relationships with the other 2 beans. So in your specific case, Person_Accounts has to be mapped to a new bean PersonAccount. Person should have one to many relationship with PersonAccount. Similarly Account will have one to many relationship with PersonAccount.
|
Sab<br /> <br />Perfection does not come from belief or faith. Talk does not count for anything. Parrots can do that. Perfection comes through selfless work.<br />Swami Vivekananda
|
 |
Mayuri Roi
Greenhorn
Joined: Oct 12, 2004
Posts: 23
|
|
|
That worked. thank you
|
 |
 |
|
|
subject: EJB Question. Add a new column to Many-to-many relation generated table.
|
|
|