This week's giveaway is in the EJB and other Java EE Technologies forum. We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line! See this thread for details.
Hey all. I need your help please. I have two CMP beans, PlayerBean and TeamBean. the relationship is one to many and unidirectional. TeamBean has a CMR field called plalyers and PlayerBean has a CMR field called team. the database schema for TeamBean is : name, city the database schema for Player bean is : id, fullname, name // name is the name of the city when designing my database, I didn't specify the name field in PlayerBean table as a FK and it is nullable ( I am allowing that a player can exists without a team) PlayerBean has the following ejbCreate( ) method :
but I have read a note that says : you must set the CMR field at the ejbPostCreate( ) like this :
I am now confused, which approach is right ? someone told me that if you designed your name field in Player table as NOT a FK , then you can use the first approach. and I you set the name field in Player table, then you must use the second approach (setting the CMR field in ejbPostCreate( )). enlight me please, I am confused.
Originally posted by John Todd: I have two CMP beans, PlayerBean and TeamBean. the relationship is one to many and unidirectional. TeamBean has a CMR field called plalyers and PlayerBean has a CMR field called team.
Correction: this is not a unidirectional relationship -- it's bidirectional because you can navigate the relationship both directions. A unidirectional relationship would have only the team.players field or the player.team field but not both.
Foreign key specifications in your database schema will not be considered by the beans themselves. You are free to declare the relationship in DDL or not as you like.
but I have read a note that says : you must set the CMR field at the ejbPostCreate( )
This is correct, regardless of whether or not you have defined the FK relationship in the database. As well, you should not be setting the player.name field directly; instead, simply set the TeamLocal in ejbPostCreate() and it will set player.name for you. It will also add the PlayerLocal to the team.players Collection.
Please ranchers, lend your hand.
I'll lend you both, and "alot" is actually two words. [ August 24, 2004: Message edited by: David Harkness ]