RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX


Banish Your Resistance to Persistence with the EJB 3.0 Persistence API

With the 3.0 version of EJB, Java's guardians have endeavored to make persistence a gentler beast that borrows the best from other ORM frameworks that have long curried favor with the community. Now, learn how to use the new spec, along with JBoss and Maven, to persist Java objects to a relational database.

lthough the EJB 3.0 specification has yet to be released, it is already generating much interest in the software development community by both proponents and opponents alike. All recognize the need to find more productive methods for developing software; the debate centers on whether, and to what extent, EJB 3.0 will play a role in this new landscape. Debate notwithstanding, the release of the EJB 3.0 public draft and preliminary support in JBoss mean that now is a great time to explore this influential technology. In fact, reports of the use of EJB 3.0 in production systems are already emerging.

This article is the second in a three-part series exploring EJB 3.0 as defined in the public draft. Each article will introduce you to particular concepts from the specification and walk you through the implementation of these techniques using JBoss.

The first article introduced EJB 3.0, the philosophy behind it, and illustrated how to use it to develop Enterprise Bean Components. This second article will introduce you to developing persistent entities with EJB 3.0. The third article will explore more advanced topics such as transaction management, security, exceptions, callbacks, and interceptors.

Example Application
In the first article I built a sample music store application that allows users to browse for albums and videos, add them to their shopping cart, and eventually purchase the items stored their cart. In this article I'll extend that application to illustrate the concepts of EJB 3.0 persistence. The storefront is shown in Figure 1.

Figure 1. Music Store: The music store allows products to be browsed, added to a shopping cart, and eventually purchased.
Figure 2. Music Store Design: In this design web, requests are handled by a Struts action that uses two EJBs (one stateless and the other stateful) to fulfill the request. At checkout the customer’s cart is passed via JMS to an order processor implemented as a MDB for fulfillment.

In the first article you saw how the storefront was designed and implemented using EJB 3.0 enterprise component beans (session and message-driven beans). This simple design is shown in Figure 2.

In this article you will enhance the application to retrieve its inventory from a database using EJB 3.0 persistence.

What You Need

Close Icon
Thanks for your registration, follow us on our social networks to keep up-to-date