Enterprise beans run in the EJB container:
- the EJB container is a runtime environment within a Java application server
- the EJB container provides system-level services to enterprise beans such as transactions and security
Content:
1 What Is an Enterprise Bean?
An enterprise bean is a server-side component that contains the application's business logic
- for example, in an auction application, the AuctionManager enterprise bean implements the business logic in the methods named
createAuction,placeBid,closeAuction.
1.1 Benefits of Enterprise Beans
Enterprise beans simplify the development of large applications:
- the EJB container, not the developer, is responsible for system level services such as transaction management and security authorization
- the beans not the clients contain the business logic, the clients only contain the presentation. As a consequence, application clients are thinner
- enterprise beans are portable, they are portable accross any compliant Java EE server and developers can build new applications from existing beans
1.2 When to Use Enterprise Beans
You should consider using enterprise beans if your application has any of the following requirements:
- the application must be scalable to support more users and you need to distribute application's components to multiple machines
- transactions must ensure data consistency
- application will be accessed by a variety of clients
1.3 Types of Enterprise Beans
There are two types of enterprise beans, which fulfill different purposes:
- Session: a session bean performs a task for a client
- Message-driven: a message-driven bean acts as a listener for messages