• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

regarding code in MZ's notes?

 
pradeep arum
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
seeing this code from MZ's notes...my question is...
public abstract class CustomerBean implements javax.ejb.EntityBean {
...
public void addPhoneNumber(String number, byte type)
throws NamingException, CreateException {
InitialContext jndiEnc = new InitialContext();
PhoneHomeLocal phoneHome = (PhoneHomeLocal)
(jndiEnc.lookup("PhoneHomeLocal"));
PhoneLocal phone = phoneHome.create(number,type);
Collection phoneNumbers = this.getPhoneNumbers();
phoneNumbers.add(phone);
}
we did a JNDI look up for a home object and then used that to create a row with a number and type and the returned EJBObect is phone...then this.phoneNumbers() will return a collection of EJBObjects for the bean in CMR....now why did we do the phoneNumbers.add(phone), because we did a create (create(number,type)) the returned collection should already have this EJBObject. and i think there is no need for the add(phone) to really add a phone number.
can somebody explain this
thanks in advance
Pradeep
 
Alibabra Sanjie
Ranch Hand
Posts: 147
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
...because we did a create (create(number,type)) the returned collection should already have this EJBObject. and i think there is no need for the add(phone) to really add a phone number.

Create only inserts an new row into the table - an database entity. It only take care of persistent part, you still have to take care of the relationship part - defining the relationship for the newly created entity (phone), adding phone number the customer. Two aspects - persistent and relationship, don't mix up!
[ March 20, 2004: Message edited by: Alibabra Sanjie ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic