• 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 all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
  • Piet Souris
  • salvin francis
  • fred rosenberger

Doubt in Mikalai Zaikin study guide !!

Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please tell me whether the data will get deleted in the database on calling the remove() on the collection returned in the EntityBean below.

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)
PhoneLocal phone = phoneHome.create(number,type);
Collection phoneNumbers = this.getPhoneNumbers();

public void removePhoneNumber(byte typeToRemove) {
Collection phoneNumbers = this.getPhoneNumbers();
Iterator iterator = phoneNumbers.iterator();
PhoneLocal phone = (PhoneLocal)iterator.next();
if (phone.getType() == typeToRemove) {

public abstract java.util.Collection getPhoneNumbers( );
public abstract void setPhoneNumbers(java.util.Collection phones);

Ranch Hand
Posts: 1683
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not sure, but I would think that remove() just removes the element from the collection. It is actually the add() method which changes the DB.

In a one-to-many relationship, just invoking add() causes the phone to be first removed. So, in order to correctly add a phone, you must first invoke removePhoneNumber() followed by addPhoneNumber().
Ranch Hand
Posts: 275
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't think HFEJB got into it too deeply, but I do think that for CMP beans, someEBObjectWithRelationship.remove(someEBObjectInRelationship) on an entity bean actually removes it from the database. Of course if you are just spinning through a collection of non-EB's, and you run remove it's not going to do anything to the database.

The examples are horrific (with A's and B's, 1's and 2's)* but this page goes into it very extensively.


* I had to re-write the examples with John, Paul, George and Ringo related to various instruments before I could really 'see' the relationships.
[ May 15, 2004: Message edited by: Dale Seng ]
What's that smell? Hey, sniff this tiny ad:
Devious Experiments for a Truly Passive Greenhouse!
    Bookmark Topic Watch Topic
  • New Topic