• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Confused a little, alot

 
clojure forum advocate
Posts: 3479
Mac Objective C Clojure
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 3479
Mac Objective C Clojure
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please ranchers, lend your hand. :roll:
 
Ranch Hand
Posts: 1646
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 3479
Mac Objective C Clojure
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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:
 
reply
    Bookmark Topic Watch Topic
  • New Topic