4.2. Running Examples

Each example has its own build.xml file; this allows each example to be run independently.

4.2.1. Stateless Session Bean

The build.xml file for this example is located in the examples/statelessbean folder.

4.2.1.1. Description

This example is a stateless session bean. It contains a helloWorld() method that displays text on the server side. Additionally, it demonstrates the use of EJB3 annotation, such as @Stateless.

The trace() method is annotated with @AroundInvoke EJB3 annotation. This method will be called at each call on a business method. The business methods are defined in the interface implemented by the SessionBean class.

The signature of the method annotated by @AroundInvoke when it is defined in the bean class, must follow this signature:

(private|protected|public) Object methodName(InvocationContext invocationContext)
    throws Exception;
[Note]Note

As a new feature of the EJB3, the bean's interface does not need to extend the Remote interface.

4.2.1.2. Running the Server

If the server is not available, it must be run by following the steps described in Chapter 3, "Running the EasyBeans Server."

4.2.1.3. Deploying the Bean

The stateless session bean must be deployed. If the bean has been installed in the ejb3s folder, this is done automatically.

On the server side, the following output should be seen:

     [java] INFO: Creating container for archive /home/benoitf/workspace/easybeans/ejb3s/stateless.jar.
     [java] INFO: Analyze elapsed during : 95 ms
     [java] INFO: Binding bean XXX with interface XXX into registry with jndi name XXX
     [java] INFO: Enhancement elapsed during : 105 ms
     [java] INFO: Container started in : 274 ms

Once this information is displayed on the screen, the container is ready to receive client calls.

4.2.1.4. Running the Client

Once the container has been started, the client can be launched.

Run the client with the following ant command: ant run.client

If the client runs successfully, the following output is displayed:

     [java] Calling helloWorld method...
     [java] Add 1 + 2...
     [java] Sum = '3'.
[Note]Note

In the client's code, the use of the PortableRemoteObject.narrow() call is no longer required.

4.2.2. Stateful Session Bean

The build.xml file for this example is located in the examples/statefulbean folder.

4.2.2.1. Description

This is an example of a stateful session bean using the SessionSynchronization interface.

It uses the @Stateful annotation and uses the default transaction model, which is REQUIRED.

4.2.2.2. Running the Server

If the server is not available, it must be run by following the steps described in Chapter 3, "Running the EasyBeans Server."

4.2.2.3. Deploying the Bean

The stateful session bean must be deployed. It is done automatically if the bean has been installed in the ejb3s folder.

On the server side, the following output should be seen:

     [java] INFO: Creating container for archive /home/benoitf/workspace/easybeans/ejb3s/stateful.jar.
     [java] INFO: Analyze elapsed during : 89 ms
     [java] INFO: Enhancement elapsed during : 76 ms
     [java] INFO: Binding bean XXX with interface XXX into registry with jndi name XXX
     [java] INFO: Container started in : 251 ms

Once this information is displayed on the screen, the container is ready to receive client calls.

4.2.2.4. Running the Client

Once the container has been started, the client can be launched.

Run the client with the following ant command: ant run.client

If the client runs successfully, the following output is displayed:

     [java] Start a first transaction
     [java] First request on the new bean
     [java] Second request on the bean
     [java] Commit the transaction
     [java] Start a second transaction
     [java] Buy 50 amount.
     [java] Rollback the transaction
     [java] after rollback, value = 30
     [java] Request outside any transaction
     [java] Check that value = 30
     [java] ClientStateful OK. Exiting.

4.2.3. Entity Bean

The build.xml file for this example is located in the examples/entitybean folder.

4.2.3.1. Description

This is an example of an entity bean. It describes how to use the new Java Persistence Model of an EJB3 persistence provider. To access EJB3 entities that are POJO, a stateless session bean is used. It is a facade bean.

The Entity class is a POJO class annotated with @Entity. The entities class is managed by the persistence provider.

Currently, the persistence provider is supplied by the Hibernate product, but the ObjectWeb Speedo product should be available soon. Users will have the choice between providers.

This example uses the @Stateful annotation and uses the default transaction model, which is REQUIRED.

The example shows an entity bean using EJB3 Hibernate-prototype persistence provider.

4.2.3.2. Running the Server

If the server is not available, it must be run following the steps described in Chapter 3, "Running the EasyBeans Server."

4.2.3.3. Deploying the Bean

The entity bean must be deployed. It is done automatically if the bean has been installed in the ejb3s folder.

On the server side, the following output should be seen:

     [java] INFO: Creating container for archive /home/benoitf/workspace/easybeans/ejb3s/entitybean.jar.
     [java] INFO: Analyze elapsed during : 95 ms
     [java] INFO: Enhancement elapsed during : 102 ms
     [java] INFO: No persistence provider was set, set to value org.hibernate.ejb.HibernatePersistence.
     [java] INFO: Hibernate 3.1.1
     [java] INFO: Using provided datasource
     [java] INFO: RDBMS: HSQL Database Engine, version: 1.8.0
     [...]
     [java] INFO: Binding bean XXX with interface XXX into registry with jndi name XXX
     [java] INFO: Container started in : 2010 ms

Once this information is displayed on the screen, the container is ready to receive client calls.

4.2.3.4. Running the Client

Once the container has been started, the client can be launched.

The client is run with the following ant command: ant run.client

If the client runs successfully, the following output is displayed:

     [java] Employee with id 1 = Florent
     [java] Employee with id 2 = Whale