EJB Samples
All EJB 3.0 samples come with JUnit unit tests that can be run in Eclipse, IntelliJ, NetBeans, Maven, Ant or any IDE or build system without special plugins using OpenEJB as an embedded EJB container. The easiest way to run the samples in your IDE is to use maven (mvn eclipse:eclipse
or mvn idea:idea
) to generate project descriptors.
Unfortunately all the examples are not documented here yet, more examples can be browsed in version control or check it out with subversion (
svn co http://svn.apache.org/repos/asf/openejb/trunk/openejb3/examples
).
title | description | APIs used |
---|---|---|
Simple EJB3 @Stateless bean with local and remote business interfaces and unit test. |
|
|
Simple Stateful | Simple EJB3 @Stateful bean with local and remote business interfaces and unit test. |
|
EJB 3.1 Singleton | Shows two EJB 3.1 @Singleton beans. One configured to load on startup via @Startup and using Bean-Managed Concurrency and synchronization. Another using Container-Managed Concurrency via @Lock(READ) and @Lock(WRITE). |
|
EJB 2.1 Compatibility | Shows an EJB 3.0 Stateful bean with Business interfaces and EJB 2.1 interfaces (now called "component" interfaces) using the @LocalHome and @RemoteHome. Four interfaces in total. |
|
Injection of env-entry | Shows how @Resource can be used to inject env-entry values declared in an ejb-jar.xml file |
|
Injection of env-entry 2 | Same as the above example but shows how to use a properties file to declare the injection values and demonstrates how to get injection of more types such as java.util.Date, java.lang.Class, java.net.URI and more. OpenEJB specific feature. |
|
Injection of other EJBs | Shows use of @EJB in a Stateless to have another Stateless bean injected into it. |
|
Injection of DataSource | Shows use of @Resource to have a JDBC DataSource injected into a Stateful bean. The Stateful bean does basic INSERT, SELECT and DELETE SQL operations. |
|
Injection of EntityManager | Shows use of @PersistenceContext to have an EntityManager with an EXTENDED persistence context injected into a @Stateful bean. An EJB 3 @Entity bean is used with the EntityManager to create, persist and merge data to a database. |
|
Testing Transactions | Shows use of @PersistenceContext to have an EntityManager with an TRANSACTION persistence context injected into a @Stateful bean using the @TransactionAttribute annotation and a TestCase that runs test code in a JTA Transaction. An EJB 3 @Entity bean is used with the EntityManager to create, persist and merge data to a database. |
|
Testing Security | Builds upon the Injection of EntityManager Example but adds the use of @RolesAllowed and @PermitAll in the @Stateful bean to restrict who can perform create, persist and remove operations on the EntityManager. Shows a TestCase using the @RunAs annotation to execute and test the bean code as various users. |
|
Embedded and Remotable | Demonstrates how to use an OpenEJB feature that allows people embedding OpenEJB into their applications to support remote clients in other VMs. This is not required for unit testing. |
|
Helloworld Weblogic | Demonstrates OpenEJBs ability to understand and support the WebLogic deployment descriptors so people using that platform in production can still use OpenEJB in their IDE or build to unit test their EJB applications. |
|
JSF Injection Support | Demonstrates OpenEJBs ability to inject EJB's into JSF managed beans. |
|
Struts with OpenEJB and Tomcat | Demonstrates the usage of Struts within an OpenEJB + Tomcat environment. |
|
Applets with OpenEJB | Demonstrates how an applet can communicate with a remote stateless session bean. The stateless session bean is deployed in an OpenEJB + Tomcat environment |
|