Data in join table apart from the foreign keys using EJB2.0 2004-03-03 - By Markus Fuchs
Back Hi Vijith,
Your problem sounds like you want to have attributes on a relationship mapped to a join table. This can be handled in the following way:
* You need to map TableC as a separate entity, say EJB3. EJB3 will have two collection relationship fields, say EJB1s and EJB2s. EJB1 and EJB2 will have object relationship fields to EJB3. * To establish a relationship between EJB1 and EJB2, set the relationships between EJB1 and EJB3 and EJB3 and EJB2 in ejbPostCreate.
HTH,
-- markus.
> > Hi All, > > I have a scenario like this > -- ---- ---- ---- ---- ------ > > TableA (col1 PK) > > TableB (col2 PK) > > TableC (col1 , col2, col3) > -- ---- ---- ---- ---- ------ > (Col1 + col2) composite PK > Col1 is FK(TableA) > Col2 is FK(TableB) > Col3 is a normal column > > -- ---- ---- ---- ---- ---- ---- --- > > Now I have designed the EJB like this > > EJB1 (Entity Object for TableA) > EJB2 (Entity Object for TableB) > > There is a many - many relationship between EJB1 and EJB2 with TableC as > join table. > > I'm following the SessionFacade pattern. In the Session Bean , I create > the entity for EJB1 and create the Entity for EJB2. In the CMR setter of > EJB1, i associate the EJB2,(though after adding it to a collection), > which populates data to TableC. > > In this way, the data is inserted into TableA, TableB and TableC like > > Table A > -- ---- > col1 > ---- > 1 > > TableB > -- --- > col2 > ---- > 1 > > TableC > -- --- > col1 col2 col3 > -- ---- ---- ------ > 1 1 null > > My requirement here is to insert data to col3 in the same transaction ie > the data should get populated in the same transaction that inserts data > into col1 and col2 of TableC.If the validation for col3 fails, all > inserts should be rolled back. > > I tried this appraoch. I created EJB3 which maps to TableC and performed > the following steps. > > Steps > -- -- > 1) In session bean, create EJB1 and get the reference to > the EJB1object > 2) In session bean, create EJB2 and get the reference to > the EJB2object > 3) create new vector with EJB2object as an element. > 4) On EJB1object , call setCMREJB2(vector); > (The above series of steps inserts data in all the table except for col3 > in TableC) > 5) Try to get the handle for the EJBObject for table3 > using findByPK(new PK(col1, col2)) > 6) But this fails as the previous transaction is not > commited and findByPK fails. So Im not able to call > setter for col3 in EJB3. > > Any suggestions :-) > > Thanks > Vijith > > =========================================================================== > To unsubscribe, send email to listserv@(protected) and include in the body > of the message "signoff J2EE-INTEREST". For general help, send email to > listserv@(protected) and include in the body of the message "help".
=========================================================================== To unsubscribe, send email to listserv@(protected) and include in the body of the message "signoff J2EE-INTEREST". For general help, send email to listserv@(protected) and include in the body of the message "help".
|
|