Skip Headers

# Managing Dependent Objects

Previous

Next

Unlike EJB, TopLink dependent persistent objects can be sent back and forth between a client and a server. When objects are serialized, the risk exists the objects can cause the cache to lose the identity of the objects or attempt to cache duplicate identical objects. To avoid potential problems, use the bean setter methods when adding dependent objects to relationship collections as Example: Managing Dependent Objects shows. This enables TopLink to handle merging of objects in the cache.

Managing Dependent Objects

    addPhoneNumber(PhoneNumber phone) {
        Collection phones = this.getPhoneNumbers();
        Vector newCollection = new Vector();
        newCollection.addAll(phones);
        newCollection.add(phone);
        this.setPhones(newCollection);
    }