aspose file tools*
The moose likes EJB and other Java EE Technologies and the fly likes Confused a little, alot Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "Confused a little, alot " Watch "Confused a little, alot " New topic
Author

Confused a little, alot

Hussein Baghdadi
clojure forum advocate
Bartender

Joined: Nov 08, 2003
Posts: 3479

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.
Hussein Baghdadi
clojure forum advocate
Bartender

Joined: Nov 08, 2003
Posts: 3479

Please ranchers, lend your hand. :roll:
David Harkness
Ranch Hand

Joined: Aug 07, 2003
Posts: 1646
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 ]
Hussein Baghdadi
clojure forum advocate
Bartender

Joined: Nov 08, 2003
Posts: 3479

(Thanks alot) * 10
AFAIK, we set the CMR field in ejbPostCreate( ) when one of the two beans can't exists without the other, right ? :roll:
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Confused a little, alot