# Tutorial: Enterprise JavaBeans

## The Big Picture

In this tutorial you will learn how to develop an application that uses Enterprise JavaBeans technology. You will build the EJBProjectTutorial application, which uses session, entity, and message-driven beans to model a music site, registering information about bands, recordings, and recording ratings. The below diagram shows the components that you will build in blue. The components in white are predefined in the tutorial.

Note. If you are new to Enterprise JavaBeans technology, you might want to consider running the Getting Started: Enterprise JavaBeans tutorial first before continuing with this tutorial. The Getting Started Tutorials is a series of short tutorials that offers a basic step-by-step introduction to the core J2EE components and how you can develop these components with WebLogic Workshop

The tutorial consists of three parts. In Part One, you will create a new application, import an existing entity bean Band and develop a stateless session bean Music. You will also add component methods and EJB references. In the final section of Part One you will test the EJBs using two different page flows. Both page flows allow you to add bands to the database and receive a listing of known bands. One page flow uses an EJB control to locate and reference an EJB while the other page flow uses Java JNDI API directly embedded in a JSP page.

In Part Two of the tutorial you will develop a second entity bean Recording, and define a relationship between bands and recordings. You will use another page flow to add bands and recordings for bands, and receive listings of recordings and bands. You will also develop a test web service to run and test the Bands bean.

In Part Three of the tutorial you will develop a message-driven bean Statistics that creates ratings for recordings. You will learn how to send a message for this bean from the Music EJB and how to store the rating information the Statistics bean generates. You will use another page flow to test the EJBs.

### Tutorial Goals

In this tutorial you will learn how to develop session, entity, and message-driven beans. Along the way you will become acquainted with advanced features such as entity relationships. Also, this tutorial shows how to build a full-fledged application by including a page flow application, and demonstrates popular design patterns used to model EJBs. The tutorial guides you through the process of adding functionality in increments and shows how to test your EJBs as you build them.

### Tutorial Overview

The following components are used in this tutorial:

- A Band entity bean, which holds information about bands.
- A Recording entity bean, which holds information about recordings.
- A Music session bean, which references the Band entity bean, and provides the interface to client applications.
- A Statistics message-driven bean, which processes messages sent by the Music bean.
- The client applications of the Music bean. In part one of the tutorial, two page flows invoke methods of the Music EJB to add a band and receive a listing of currently known bands. One of these page flows uses an EJB control to communicate with the Music bean. In part two of the tutorial, a page flow invokes the methods of the Music bean to add a band, receive a listing of currently known bands, and, for a given band, add a recording and receive a listing of currently known recordings. In part three of the tutorial, a page flow is used that incorporates all the functionality of the page flow used in part two, plus enables you to view rating information of recordings. The page flows in parts two and three of the tutorial use EJB controls to communicate with the Music bean.
- The test web service of the Band bean. This web service is meant to be used for testing purposes only during development. It allows you to quickly run and test a bean without having to be involved in the (re)design of page flows. The test web service uses an EJB control to communicate with the Band bean.
- A database that will hold the tables used to store information about recordings and bands.
- A JMS provider and queue to send messages to. You will use a provider available in the domain and create the JMS queue.

The entity beans in this tutorial perform operations on database tables that hold information about bands and recordings. The session bean encapsulates the business logic of the music site. It serves as an intermediary between client applications and the entity beans - a common design pattern called Session Façade - and also sends JMS messages. The message-driven bean, which processes these JMS messages, invokes an entity bean to store information generated during the processing of a message. Message-driven beans are frequently used in this manner to enable asynchronous handling of business tasks that require involvement of session and/or entity beans.

### Parts in This Tutorial

Part One: Building Your First EJBs

In this part you will create the first set of Enterprise JavaBeans in the tutorial. You will start WebLogic Workshop and WebLogic Server, create a new application and EJB project, import an entity bean that represents band objects, and develop the session bean Music.

Part Two: Defining an Entity Relationship

In the second part of the tutorial you will add a second entity bean holding information about recordings, define the relationship between bands and recordings, and update the session bean to enable client applications to add recordings and receive listings of recordings for bands.

Part Three: Adding a Message-Driven Bean

In part three of the tutorial you will add a message-driven bean that will generate rating information for a recording, update the Recording bean to store this information, and update the session bean to send a message for the message-driven bean and enable client applications to view ratings.

Summary: Enterprise JavaBean Tutorial

Reviews what you have done in this tutorial.

To begin the tutorial, see Part One: Building Your First EJBs. You can also click the arrow to navigate to this next step.