• 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

My last 2 Qs about CMR please

 
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 have two CMP beans, CustomerEJB and AddressEJB.
the database schema for address is :
ID, STREET, CITY
the database schema for customer is :
NAME, EMAIL, ADDRESS_ID (ADDRESS_ID is FK)
the CustomerBean class has the following methods :
public abstract void setName(String) // and getName( )
public abstract void setEmail(String) // and getEmail( )
public abstract AddressLocal getAddress( ) // and setAddress( )
its obvious that setAddress( ) is for setting the CMR field.
my 2 questions :
1. we don't create the following CMR field in ejb-jar.xml :
<cmp-field><field-name>addressId</field-name></cmp-field>
because the container will fill the ADDRESS_ID of Customer table automaticlly, right ?
2. we set the CMR field in ejbPostCreate( ) method, only when one of the beans can't exists without the other.
the PlayerBean can exists without a TeamBean, so we don't set team CMR field of PlayerBean in ejbPostCreate( ) method.
but we need to set addressLocal CMR field of CustomerBean in ejbPostCreate( ) because the address must be associated with a customer (assuming the design requires this).
 
Ranch Hand
Posts: 401
  • 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:

1. we don't create the following CMR field in ejb-jar.xml :
<cmp-field><field-name>addressId</field-name></cmp-field>
because the container will fill the ADDRESS_ID of Customer table automaticlly, right ?



No, you have to specify all relations for your cmr fields in the <relationships > part of ejb-jar.xml. The container will not create this for you, it's your job to specify all mappings.
If you don't know how the <relationships> tag work, take a look at any j2ee reference.


Originally posted by John Todd:
2. we set the CMR field in ejbPostCreate( ) method, only when one of the beans can't exists without the other.
the PlayerBean can exists without a TeamBean, so we don't set team CMR field of PlayerBean in ejbPostCreate( ) method.
but we need to set addressLocal CMR field of CustomerBean in ejbPostCreate( ) because the address must be associated with a customer (assuming the design requires this).



I think your misunderstanding some important things. If a cmr should be created or not is part of your business logic and not part of the ejb spec. What should be clear is that whenever you need to create a cmr field, it must be in ejbPostCreate().
So, if in your application player may exist without a team, it wouldn't make sense to create cmr fields for team in players bean ejbPostCreate(). But if for anyreason, your league rules change and now players must be associated to teams to existe, you must set the players teams in ejbPostCreate().
[ August 28, 2004: Message edited by: Leandro Melo ]
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic