Troubleshooting
Problem
Learning more about EJBs, EJB Container and Embeddable EJB Container is the first step in the troubleshooting process. This document provides you with educational information that can help you learn more about this topic.
Resolving The Problem
Tab navigation
- Learn more- selected tab,
- Troubleshoot
- Collect data
Introduction to EJBs / EJBContainer and Embeddable EJB container
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 JavaBeans (EJB) containers, which provide an interface between the beans and the application server on which they reside.
Entity beans and JPA overview
EJB 2.1 and earlier versions of the specification define entity beans as a means to store permanent data, so they require connections to a form of persistent storage. This storage might be a database, an existing legacy application, a file, or another type of persistent storage.
The EJB 3.0 specification introduced the Java Persistence API (JPA) specification as the intended replacement to EJB 2.x style entity 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.
Furthermore it is important to know that Entity beans as described in the EJB 2.1 specification (and earlier) were declared optional in the EJB 3.2 specification and are not supported in WebSphere Application Server Liberty, but JPA can be used.
Session beans overview
Session beans typically contain the high-level and mid-level business logic for an application. Each method on a session bean performs a particular high-level operation. For example, submitting an order or transferring money between accounts. Session beans often invoke methods on entity beans in the course of their business logic.
Session beans can be singelton, stateful or stateless. A stateful bean instance is intended for use by a single client during its lifetime, where the client performs a series of method calls that are related to each other in time for that client. One example is a shopping cart where the client adds items to the cart over the course of an online shopping session. In contrast, a stateless bean instance is typically used by many clients during its lifetime, so stateless beans are appropriate for business logic operations that can be completed in the span of a single method invocation. Stateful beans should be used only where absolutely necessary. Using stateless beans improves the ability to debug, maintain, and scale the application.
The EJB 3.0 specification simplifies session beans. They often invoke method on JPA entities or EJB entity beans in the course of their business logic:
- Define the business interface (optional)
- Define the class that implements it.
- Add metadata with annotations or with XML deployment descriptors.
Singleton Session Beans
Introduced in the EJB 3.1 specification, a singleton session bean is instantiated once per application and exists for the lifecycle of the application. Singleton session beans are designed for circumstances in which a single enterprise bean instance is shared across and concurrently accessed by clients.
EJB annotations overview
Starting with the EJB 3.0 specification, all EJB configuration that can be specified in ejb-jar.xml may also be specified using annotations. There are two types of annotations:
- component defining annotations
- reference/injection annotations
EJB components, Web components, and application clients can use annotations such as @EJB and @Resource to declare EJB and resource references and the injection of those references. For EJB references defined either in ejb-jar.xml or with the @EJB annotation, the application may allow the EJBContainer to dynamically bind the reference to the EJB (auto-link) if the referenced bean is located in the same enterprise archive (EAR) file. Otherwise, the application must provide a binding for the reference in either the ibm-ejb-jar-bnd.xml file or ibm-web-bnd.xml file (which may be set during application install). For more information about reference bindings, see the topic "EJB 3.0 and EJB 3.1 application bindings overview" in the Knowledge Center. The reference to that page can be found below in the "Related information" section.
EJB implementation classes may be configured using the @Stateless, @Stateful, @Singleton, and @MessageDriven annotations. The interfaces for an EJB may be configured using @Local, @Remote, @LocalHome, @RemoteHome and @LocalBean. There are several other component defining annotations related to transaction settings, timers, lifecycle, etc.
Message driven beans overview
Message-driven beans enable asynchronous message servicing.
- The EJB container and a Java Message Service (JMS) provider work together to process messages. When a message arrives from another application component through JMS, the EJB container forwards it through an onMessage method call to a message-driven bean instance, which then processes the message. In other respects, message-driven beans are similar to stateless session beans.
- The EJB container and a Java Connector Architecture (JCA) resource adapter work together to process messages from an enterprise information system (EIS). When a message arrives from an EIS, the resource adapter receives the message and forwards it to a message-driven bean, which then processes the message. The message-driven bean is provided services such as transaction support by the EJB container in the same way that other enterprise beans are provided service.
EJBContainer overview
An Enterprise JavaBeans (EJB) container provides a run-time environment for enterprise beans within the application server. The container handles all aspects of an enterprise bean's operation within the application server and acts as an intermediary between the user-written business logic within the bean and the rest of the application server environment.
One or more EJB modules, each containing one or more enterprise beans, can be installed in a single container.
The EJB container provides many services to the enterprise bean, including the following:
- Beginning, committing, and rolling back transactions as necessary.
- Maintaining pools of enterprise bean instances ready for incoming requests and moving these instances between the inactive pools and an active state, ensuring that threading conditions within the bean are satisfied.
- Most importantly, automatically synchronizing data in an entity bean's instance variables with corresponding data items stored in persistent storage.
Embeddable EJB container overview
The embeddable Enterprise JavaBeans (EJB) container is a container for enterprise beans that do not require a Java Platform, Enterprise Edition (Java EE). The WebSphere® Application Server embeddable EJB container is a container for enterprise beans that does not require a Java EE server to run. The EJB programming model and the EJB container services are now available for Java Platform, Standard Edition (Java SE) server.
The following are embeddable container usage scenarios:
- EJB unit testing: developers can test their enterprise beans without needing a full server installation of WebSphere Application Server in their development environment.
- Embedding enterprise beans in Java SE applications: developers can use enterprise beans and the functionality that is provided with an EJB container, for example, dependency injection, transactions, and security in stand-alone desktop applications.
- No server installation is necessary for EJB development, unit testing, and Java SE-based application deployment.
- The embeddable container is a much smaller footprint, in terms of disk space and main memory, than the server-based container.
- The embeddable container starts faster than the server-based container because it initializes only EJB-related components.
- Inbound RMI/IIOP calls are not supported, which means that all EJB clients must exist within the same Java virtual machine (JVM) as the embeddable container.
- Message driven beans (MDB) are not supported.
- The embeddable container cannot be clustered for high availability per workload management. For a complete list of supported functions in the WebSphere embeddable container, see the topic, Embeddable EJB container functions.
Related Information
Was this topic helpful?
Document Information
Modified date:
15 June 2018
UID
swg22008636