Java Reference
In-Depth Information
import javax.ejb.SessionBean;
import javax.ejb.SessionContext;
public class CatalogBean implements SessionBean {
private SessionContext ctx;
public String getJournal(String publisher) {
if (publisher.equals("Oracle Publisher"))
return new String("Oracle Magazine");
if (publisher.equals("OReilly"))
return new String("dev2dev");
public void ejbCreate() {
public void ejbRemove() {
public void ejbActivate() {
public void ejbPassivate() {
public void setSessionContext(SessionContext ctx) {
this.ctx = ctx;
In EJB 3.0, metadata annotations are used to specify the session bean type and
local and remote business interfaces. A stateless session bean is specified with the
annotation @Stateless , a stateful session bean with the annotation @Stateful .
Component and home interfaces are not required for a session bean. A session bean
is required to implement a business interface. The business interface, which is a POJI,
may be a local or remote interface. A local interface is denoted with the annotation
@Local and a remote interface is denoted with the annotation @Remote . A session
bean may implement one or both (local and remote) of the interfaces. If none of the
interfaces is specified, a local business interface gets generated. The remote and local
business interface class may be specified in the @Local and @Remote annotations.
For example, a local business interface may be specified as
@Local ({CatalogLocal.class}) .
The EJB 3.0 session bean corresponding to the EJB 2.x stateless session bean is
annotated with the metadata annotation @Stateless . The EJB 3.0 bean class does
not implement the SessionBean interface. The EJB 3.0 session bean implements a
business interface. The @Local annotation specifies the local business interface for
the session bean. The EJB 3.0 session bean corresponding to the EJB 2.x example
session bean is listed next:
Search WWH ::

Custom Search