Each example has its own build.xml
file in
order to be independent from each other.
The build.xml
file to use is in examples/statelessbean
folder.
This example is a stateless session bean. It contains an
helloWorld()
method which displays a text on
the server side. Also, it demonstrates the use of EJB3 annotation like
@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, needs to follow this signature :
(private|protected|public) Object methodName(InvocationContext invocationContext)
throws Exception;
![]() | Note |
---|---|
As a new feature of the EJB3, the bean's interface doesn't need to extend anymore the Remote interface. |
If the server is not available, it needs to be run by following the steps described in this guide.
The stateless session bean needs to be deployed. It is done
automatically if the bean has been installed in ejb3s
folder.
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
If these informations are on the screen, it means that the container is ready to receive client calls.
As 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] Calling helloWorld method... [java] Add 1 + 2... [java] Sum = '3'.
![]() | Note |
---|---|
In the client's code, the use of PortableRemoteObject.narrow() call is not required anymore. |
The build.xml
file to use is in examples/statefulbean
folder.
This example is a stateful session bean using the
SessionSynchronization
interface.
It uses the @Stateful annotation and use the default transaction model which is REQUIRED.
If the server is not available, it needs to be run by following the steps described in this guide.
The stateful session bean needs to be deployed. It is done
automatically if the bean has been installed in 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
If these informations are on the screen, it means that the container is ready to receive client calls.
As 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] 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.
The build.xml
file to use is in examples/entitybean
folder.
This example is an entity bean.
It describes how to use the new Java Persistence Model of an EJB3 persistence provider. To access EJB3 entities which 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 are managed by the persistence provider.
Currently the persistence provider is provided by the Hibernate product, but ObjectWeb Speedo product should be used sooner. Users will have the choice between providers.
It It uses the @Stateful annotation and use the default transaction model which is REQUIRED.
This example shows the use of an entity bean and using EJB3 persistence provider which is in this prototype Hibernate. In a next version, the ObjectWeb Speedo product will provide an EJB3 persistence provider, so users will have the choice between these providers.
If the server is not available, it needs to be run by following the steps described in this guide.
The entity bean needs to be deployed. It is done automatically
if the bean has been installed in 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
If these informations are on the screen, it means that the container is ready to receive client calls.