Relationship Fields
Entity beans can form relationships with other entity beans. In Figure 6-1, at the beginning of this chapter, the Customer EJB is shown to have a one-to-one relationship with the Address EJB. The Address EJB is a fine-grained business object that should always be accessed in the context of another entity bean, which means it should have only local interfaces and not remote interfaces. An entity bean can have relationships with many different entity beans at the same time. For example, we could easy add relationship fields for Phone, CreditCard, and other entity beans to the Customer EJB. At this point, however, we’re choosing to keep the Customer EJB simple.
Following Figure 6-1 (earlier in the chapter) as a guide, we define the Address EJB as follows:
package com.titan.address;
import javax.ejb.EntityContext;
public abstract class AddressBean implements javax.ejb.EntityBean {
public Integer ejbCreateAddress(String street, String city, String state, String zip) { setStreet(street); setCity(city); setState(state); setZip(zip); return null; } public void ejbPostCreateAddress(String street, String city, String state, String zip) { } // persistence fields public abstract Integer getId(); public abstract void setId(Integer id); public abstract String getStreet(); public abstract void setStreet(String street); public abstract String getCity(); public abstract void setCity(String city); public abstract String getState(); public abstract void setState(String state); ...
Get Enterprise JavaBeans, Third Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.