You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 2 Next »

This example shows how to combine Spring, OpenEJB and Hibernate using the integration code provided by OpenEJB. Here, OpenEJB is used as an embeddable EJB container inside of Spring. See the Spring page for details.

We use the basic Movie example and expand it to include more objects to demonstrate both Spring beans, EJB Session beans, and JPA persistent objects in one application. The premise of the example is a Cineplex that has a number of Theaters (viewing screens), each playing a number of Movies. The basic object layout is as follows:

Object

Type

Description

CineplexImpl

@Stateless

Shows the use of @Resource to have Spring beans injected. Specifically, the Theaters Spring bean

Theaters

Spring bean

Simple wrapper object injected into CineplexImpl

Theater

Spring bean

Shows that EJBs can be injected into Spring beans. Uses both the Movies EJB and the Movie JPA objects

MoviesImpl

@Stateful

Wraps a JPA EntityManager and provides transactional access to the persistent Movie objects

Movie

@Entity

Basic JPA bean that is used both by Spring beans and EJBs. The same Movie object as in all the other persistence related examples.

AvailableMovies

Spring bean

Simple object used as a clever way to seed the EntityManager (and really, the database) with persistent Movie objects

Required jars

To setup the integration you'll need:

  1. The standard OpenEJB 3.1 libraries
  2. The openejb-spring-3.1.jar or later
  3. Spring 2.5 or other (any version should work)

The Spring xml

Bootstrapping and Configuring OpenEJB is fairly simple.

Error formatting macro: snippet: java.lang.NullPointerException

As well, you can optionally declare any resources or containers. Anything declarable as a <Resource> or <Container> in the openejb.xml can instead be declared in the Spring xml file as shown here.

Error formatting macro: snippet: java.lang.NullPointerException

And finally our Spring beans.

Error formatting macro: snippet: java.lang.NullPointerException
  • No labels