HomeOracle Page 2 - Managing OC4J and Configuring J2EE Applications
Enterprise JavaBeans - Oracle
This article will help you get a better grasp of how Oracle Application Server 10g supports Java 2EE applications. It is excerpted from chapter eight of the book Oracle 10g Application Server Exam Guide, written by Sam Alapati (McGraw-Hill; ISBN: 0072262710).
Enterprise JavaBeans (EJBs) are Java components that implement business logic. EJBs follow JavaSoftís specifications. You use Enterprise JavaBeans to implement the business logic in your J2EE applications. While you must use JavaBeans as part of an application, Enterprise JavaBeans are self-contained J2EE components that can service usersí requests. EJBs live inside, and are always run inside, an EJB container, which provides the necessary support infrastructure, such as connectivity to clients and other EJBs, as well as access to server resources, connectivity, and transactional support.
Note that you must deploy an EJB inside a J2EE container, unlike regular JavaBeans. A client application can access an EJB, which contains the business logic, only through a container.
An EJB can either use JDBC connections to connect directly to a database or let the container handle the database connectivity for it. The container holding an EJB is responsible for satisfying requests made by clients by either instantiating an EJB afresh, or letting the client access an already running EJB. The container will maintain the transactions, security issues, and other EJB operational details.
There are three basic types of Enterprise JavaBeans, which are described brieﬂy in the following subsections.
Session EJBs Session EJBs support a client during the execution of its tasks and last only as long as the clientís session does. You can have stateful or stateless EJBs. A stateless session EJB wonít store the state between method calls, whereas a stateless session EJB maintains state. Each stateful EJB is associated with a single client only.
Entity EJBs Entity EJBs represent an object of data, usually of a persistent nature, such as the table rows in a database. Similar to database data, Entity EJBs have a primary key to uniquely identify them. Usually, the container wherein the Entity EJBs resides will implement the database connectivity for the entity EJBs.
Entity EJBs can reﬂect two types of persistence: container-managed persistence (CMP) and bean-managed persistence (BMP). Persistence in this context refers to database transactions. When session beans choose container-managed persistence, the bean writer declares necessary transaction attributes in the deployment descriptor. The EJB container then manages the transactions automatically, without the bean writer having to write code for transaction management. Under bean-managed persistence, the user transaction interface is used to manage transactions. The bean writer decides when, exactly, the transactions are committed or rolled back instead of the container itself deciding it. The recommended approach is to use CMP in preference to BMP.
Message-Driven EJBs Message-Driven EJBs represent the integration between Java Message Service (JMS) and EJBs. These EJBs perform asynchronous messaging within the server, serving as JMS Message Listeners instead of interacting directly with clients and becoming involved in client transactions. When clients publish messages to JMS destinations, the JMS provider and the EJB container coordinate their work in delivering the message to the message-driven EJBs.
With this quick review of J2EE, letís turn our attention to OC4J, which is the framework for the development and deployment of EJB applications in the Oracle Application Server.