This week's book giveaway is in the JavaScript forum.
We're giving away four copies of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js and have Paul Jensen on-line!
See this thread for details.
Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Create this method ?  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
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 question is :
should I create the following methods in order to insert values into ADDRESS_ID field or its container responsibility to do so :
public abstract void setAddressContent(String) // and getAddressContent( )
 
David Harkness
Ranch Hand
Posts: 1646
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by John Todd:
should I create the following methods in order to insert values into ADDRESS_ID field or its container responsibility to do so :
public abstract void setAddressContent(String) // and getAddressContent( )

I'm not sure why you'd call it "addressContent" versus "addressId," but no, you do not need to create them. Some containers will in fact give you an error if you define setAddressId(). Adding a getAddressId() method can be handy for debugging, but it's not necessary.

With CMR, the container manages the SQL aspects of the relationship: setting foreign keys and performing joins.
 
Hussein Baghdadi
clojure forum advocate
Bartender
Posts: 3479
Clojure Mac Objective C
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks alot David..
I have some questions (Please be patient).
1. So, we don't need to create a method like
public abstract void setAddressId(String)
nor to create a CMP field inside the ejb-jar.xml like this :
<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).
thank you David.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!