Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

In this example we develop a simple calculator stateless session EJB.

It is an EJB 3 style pojo stateless session bean
Every stateless session bean implementation must be annotated
using the annotation @Stateless or marked that way in a deployment descriptor.

The Stateless bean has 2 business interfaces: CalculatorRemote, a remote business
interface, and CalculatorLocal, a local business interface

Local business interface
Tip
title@Local annotation

Note that it's not mandatory to annotate local business interfaces with the @Local annotation. If a business interface doesn't have any annotation, it's assumed to be local by the ejb container.

Wiki Markup
{snippet:id=code|url=openejb3/examples/calculator-stateless-pojo/src/main/java/org/apache/openejb/examples/calculator/CalculatorLocal.java|lang=java}

You'll notice that in EJB 3.0 the Local Business Interface of a stateless session bean does not need to extend from javax.ejb.EJBLocalObject and does not need a javax.ejb.EJBLocalHome interface. When the bean is looked up from JNDI, the container will create a new reference and pass it to the caller. No home interface required.

Remote business interface
Wiki Markup
{snippet:id=code|url=openejb3/examples/calculator-stateless-pojo/src/main/java/org/apache/openejb/examples/calculator/CalculatorRemote.java|lang=java}

As stated above, the Remote Business Interface of a bean can be any plain old interface. It does not need to extend javax.ejb.EJBObject, it does not need a javax.ejb.EJBHome, the methods do not need to throw javax.rmi.RemoteException, and the bean class can implement it!

Bean
Wiki Markup
{snippet:id=code|url=openejb3/examples/calculator-stateless-pojo/src/main/java/org/apache/openejb/examples/calculator/CalculatorImpl.java|lang=java}

In EJB 3.0 session beans do not need to implement the javax.ejb.SessionBean interface. You can simply annotate it as @Stateless if you want it to be a stateless session bean. And as noted above, notice the bean is actually implement the business interfaces! In the prior version of EJB implementing the remote interface (which derives from javax.ejb.EJBObject) in your bean was just not allowed. Now there is no javax.ejb.EJBObject requirement, so implementing the business interfaces is standard practice for EJB 3.0.

Writing a unit test for the example

...