This week's giveaway is in the Threads forum.
We're giving away four copies of Java Concurrency Live Lessons and have Doug Schmidt on-line!
See this thread for details.
Win a copy of Java Concurrency Live Lessons this week in the Threads forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

My last 2 Qs about CMR please  RSS feed

 
Hussein Baghdadi
clojure forum advocate
Bartender
Posts: 3479
Clojure Mac Objective C
  • Mark post as helpful
  • send pies
  • 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).
 
Leandro Melo
Ranch Hand
Posts: 401
  • Mark post as helpful
  • send pies
  • 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 ]
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!