Creating enterprise beans

After you have created your Java or EJB project, you can create session beans, entity beans, and message-driven beans to add to your project.

Enterprise beans

An enterprise bean is a Java component that can be combined with other resources to create Java applications. There are three types of enterprise beans: entity beans, session beans, and message-driven beans. All beans reside in Enterprise Java beans (EJB) containers, which provide an interface between the beans and the application server on which they reside.

The EJB 3.0 specification deprecates EJB 1.1-style entity beans. The Java Persistence API (JPA) specification is intended to replace the deprecated enterprise beans. While the JPA replacement is called an entity class, it should not be confused with entity enterprise beans. A JPA entity is not an enterprise bean and is not required to run in an EJB container.

 

Component-defining annotations

Using component-defining annotations, you can create the following types of enterprise beans: Session beans, Message-driven beans and JPA entities. Including the component-defining annotation @Stateful or @Stateless indicates that the class is a session bean class; including the component-defining annotation @MessageDriven indicates that the class is a Message-driven bean class; and including the component-defining annotation and @Entity indicates that the class is a JPA entity.

Guidelines for developing EJBs

While EJB 3.0 provides a flexible and simple programming model, here are a few of the suggested rules for developing EJBs:

You can create enterprise beans in one of the following ways:

 

Related tasks

Creating EJB projects

Creating enterprise beans using wizards

Creating enterprise beans using annotations

Importing JAR files to EJB 3.0 projects