• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Confused a little, alot

 
Hussein Baghdadi
clojure forum advocate
Bartender
Posts: 3479
Clojure Mac Objective C
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3479
Clojure Mac Objective C
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please ranchers, lend your hand. :roll:
 
David Harkness
Ranch Hand
Posts: 1646
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3479
Clojure Mac Objective C
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
(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:
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic