O'Reilly logo

Enterprise JavaBeans, Fourth Edition by Richard Monson-Haefel, Bill Burke, Sacha Labourey

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Relationship Fields

Entity beans can form relationships with other entity beans. In Figure 6-1, at the beginning of this chapter, the Customer EJB has 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 easily add relationship fields for Phone, CreditCard, and other entity beans to the Customer EJB. At this point, we’re choosing to keep the Customer EJB simple.

Using Figure 6-1 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); public abstract String getZip( ); public abstract ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required