bea.com | products | dev2dev | support | askBEA

Download Docs | Site Map | Glossary
Search

Programming WebLogic Enterprise JavaBeans

Introducing WebLogic Server Enterprise JavaBeans

WebLogic Server includes an implementation of Sun Microsystems Enterprise JavaBeans (EJB) architecture as defined by Sun's EJB specification.

Note: WebLogic Server is compliant with the Sun J2EE specification and EJB 1.1 and EJB 2.0 specifications. Except where descriptions of EJB features and behaviors make specific mention of EJB 1.1 or EJB 2.0, all information in this guide relates to both implementation. You can deploy existing EJB 1.1 beans in this version of WebLogic Server. However, if you are developing new beans, we recommend that you develop EJB 2.0 beans.

The following sections provide an overview of the EJB features and introduce the changes in the WebLogic Server's Enterprise JavaBeans implementation:

- Overview of Enterprise JavaBeans

- Implementation of Java Specifications

- WebLogic Server EJB 2.0 Support

- EJB Roles

- EJB Enhancements in WebLogic Server 7.0

- EJB Developer Tools

Overview of Enterprise JavaBeans

Enterprise JavaBeans are reusable Java components that implement business logic and enable you to develop component-based distributed business applications. EJBs reside in an EJB container, which provides a standard set of services such as persistence, security, transactions, and concurrency. Enterprise JavaBeans are the standard for defining server-side components. WebLogic Server's implementation of the Enterprise JavaBeans component architecture is based on Sun Microsystems EJB specification.

EJB Components

An EJB consists of three main components:

- Remote interface. This interface exposes business logic to the client.

- Home interface. The EJB factory. Clients use this interface to create, find, and remove EJB instances.

- Bean class. This interface implements business logic.

To create an EJB, you code a distributed application's business logic into the EJB's implementation class; specify the deployment parameters in deployment descriptor files; and package the EJB into a JAR file. You can then deploy the EJB individually from a JAR file, or package it along with other EJBs and a Web application into an EAR file, which you then deploy on WebLogic Server. Client applications can locate the EJB and create an instance of the bean using the bean's home interface. The client can then invoke the methods of the EJB using the EJB's remote interface. WebLogic Server manages the EJB container and provides access to system-level services such as database management, security management, and transaction services.

Types of EJBs

The EJB specification defines the following four types of Enterprise JavaBeans:

- Stateless session. An instance of these non-persistent EJBs provides a service without storing an interaction or conversation state between methods. Any instance can be used for any client. Stateless session beans can use either container-managed or bean-managed transaction demarcation.

- Stateful session. An instance of these non-persistent EJBs maintains state across methods and transactions. Each instance is associated with a particular client. Stateful session beans can use either container-managed or bean-managed transaction demarcation.

- Entity. An instance of these persistent EJBs represents an object view of the data, usually rows in a database. An entity bean has a primary key as a unique identifier. Entity bean persistence can be container-managed or bean-managed, but uses container-managed transaction demarcation only.

- Message-driven. An instance of these EJBs is integrated with the Java Message Service (JMS) to enable message-driven beans to act as a standard JMS message consumer and perform asynchronous processing between the server and the JMS message producer. The WebLogic Server container directly interacts with a message-driven bean by creating bean instances and passing JMS messages to those instances as necessary. Message-driven beans can use either container-managed or bean-managed transaction demarcation.

Note: Message driven beans are part of the Sun Microsystems EJB 2.0 specification. They are not part of the EJB 1.1 specification.

Implementation of Java Specifications

WebLogic Server is compliant with the following Java Specifications.

J2EE Specification

WebLogic Server 7.0 is compliant with the J2EE 1.3 specification.

EJB 2.0 Specification

The Enterprise JavaBeans 2.0 implementation in WebLogic Server is fully compliant and can be used in production.

Securing WebLogic Server EJB Resources

The vast majority of business applications apply some means of securing application resources so that only certain users can access such resources under certain conditions. WebLogic Server includes robust functionality to protect your EJB resources in this way.

The Securing WebLogic Resources guide gives background information application on and steps you through securing all WebLogic Server application resources, including EJBs.

WebLogic Server EJB 2.0 Support

WebLogic Server supports an implementation of Sun Microsystems's EJB 2.0 specification and is compliant with the Sun Microsystem's EJB 1.1 specification. In most cases, you can use EJB 1.1 beans with this version of WebLogic Server. However, in a few cases you may need to migrate existing EJB deployments from earlier versions of WebLogic Server to this version of the EJB container. If necessary, see the information on DDConverter for instructions on converting the beans.

Sun Microsystem's EJB 2.0 specification supports the following new features:

- New type of EJB called message-driven bean that is a Java Messaging Service (JMS) consumer. See Designing Message-Driven Beans, for more information.

- New entity EJB container-managed persistence model that provides a new way of handling container-managed persistence. See WebLogic Server Container-Managed Persistence Service, for more information.

- Model for creating container-managed relationships between entity EJBs allows you to define the relationship between the beans in the implementation classes and the deployment descriptors. See WebLogic Server Container-Managed Persistence Service, for more information.

- New standard query language called EJB-QL which you use to query EJBs and their properties. See WebLogic Server Container-Managed Persistence Service, for more information.

- New ejbSelect methods that allow an entity EJB to internally query for properties using an EJB-QL query defined in a deployment descriptor. See WebLogic Server Container-Managed Persistence Service, for more information.

- Local interfaces for session and entity beans. EJB relationships are now based on the local interface. Any EJB that participates in a relationship must have a local interface. See WebLogic Server Container-Managed Persistence Service, for more information.

- Home methods that allow you to execute a home business method that is not specific to a particular instance of an entity bean. You use the home interface to define one or more home methods for the entity bean See Designing EJBs, for more information.

EJB Roles

The process of developing EJBs is divided into the following distinct roles.

Application Roles

- Enterprise Bean Providers—Enterprise Bean Providers produce the EJBs. Their output is the ejb.jar file that contains one or more EJBs. The providers use the design process documented in this guide to design the EJBs that are deployed in the WebLogic Server environment.

  For more information on the design process, see Designing EJBs.

- Application Assemblers—Application Assemblers combine the EJBs into deployable units such as JARs, EARs, or WARs. Their output is the JAR, EAR, or WAR file that contains the EJB and the application assembly instructions; these instructions are set by the EJB's deployment descriptors. The assemblers use the design process and the EJB deployment descriptor elements to assemble the deployment unit.

  For more information in the design process, see Designing EJBs. For more information in the assembly process, see Packaging EJBs for the WebLogic Server Container. For more information on the deployment descriptors, see weblogic-ejb-jar.xml Document Type Definitionsand weblogic-cmp-rdbms- jar.xml Document Type Definitions.

Infrastructure Roles

- Container Providers—Container Providers supply EJB deployment tools, container monitoring and management tools, and runtime support for deployed EJB instances. This support includes services such as transaction and security management, network distribution of clients, and scalability. The container providers use the container management process documented in this guide to provide the container.

  For more information on the container management process, see The WebLogic Server EJB Container and Supported Services.

- Persistence Manager Providers—Persistence Manager Providers are responsible for persistence support for the Entity EJBs in the container, if the EJB has container-managed persistence. This support is provided during deployment to generate the code that moves data between the EJB and a database. The persistence manager providers use the deploy process and container-managed persistence (CMP) information documented in this guide to provide container-managed persistence.

  For more information on container-managed persistence, see WebLogic Server Container-Managed Persistence Service. For more information on the deploy process, see Packaging EJBs for the WebLogic Server Container.

Deployment and Management Roles

- Deployers—Deployers, following the application assembly instructions in the deployment descriptors, deploy the EJBs contained in the JAR, EAR, or WAR file to the target environment. The target environment includes the WebLogic Server environment and the container. The deployer's output is the EJB customized for the target environment and deployed in a specific EJB container. The deployers use the deploy process documented in this guide to deploy the EJBs.

  For more information on the deploy process, see Deploying EJBs to WebLogic Server.

- System Administrators—System Administrators configure and administer the computing and networking infrastructure that includes WebLogic Server and the container. System Administrators use the administration process documented in the Administration Guide and the WebLogic Server online help to manage the deployed applications at runtime.

  For more information on system administrator's tasks, see the Administration Guide.

EJB Enhancements in WebLogic Server 7.0

The following EJB enhancements are new to this release of WebLogic Server.

Changed Deployment Elements in WebLogic Server 7.0

For information about new, changed, or deprecated deployment elements in weblogic-ejb-jar.xml, see Changed Deployment Elements in WebLogic Server 7.0 EJB.

Dynamic Query Support

Dynamic queries allow you to construct and execute queries programmatically in your application code. Therefore, all finder queries no longer need to be static and hardcoded into an EJB's deployment descriptor. This gives you the ability to create and execute new queries without having to update and redeploy an EJB and reduces the size of the EJB's deployment descriptor. See Using Dynamic Queries for more information on dynamic queries.

Message-Driven Bean Migratable Service Support

Message-driven bean migratable service support allows the message-driven bean and the Java Messaging Service (JMS) server to migrate to another server in the same cluster, to expedite message-driven bean recovery. In previous versions of WebLogic Server, there was no recovery mechanism for the JMS server and the message-driven bean when a server failed. See Message-Driven Bean Migratable Service for more information on the message-driven bean migration service.

EJB CMP Multiple Table Mapping Support

Multiple table mapping allows you to map a single EJB to multiple DBMS tables within a single database. You use the WebLogic Server-specific CMP container XML deployment descriptors to map multiple DBMS tables and columns to the EJB and its fields. See Multiple Table Mapping for EJB 2.0 CMP for more information on multiple table mapping.

EJB WebLogic QL Enhancements Support

EJB WebLogic QL enhancements support in this release of WebLogic Server includes a set of enhancements to the WebLogic QL query language. WebLogic QL is a WebLogic-specific extension of the EJB 2.0 Query Language known as EJB QL. This enhancement supports the following features:

- Subqueries

- Aggregate functions

- Queries returning ResultSets

  See Using EJB QL for EJB 2.0 for more information on these three EJB WebLogic QL enhancements.

- SELECT FOR UPDATE with NO WAIT

  See Special Note for Oracle Databases for more information on this EJB WebLogic QL enhancement in TRANSACTION_READ_COMMITTED UPDATES.

Optimistic Concurrency Support

Optimistic concurrency support is a new concurrency strategy offered by WebLogic Server. Provides optimistic support with and without caching. The EJB guarantees that the data is consistent by making sure that it was not modified before committing the transaction. See Optimistic Concurrency Strategy for more information on this feature.

ReadOnly Entity Concurrency Support

ReadOnly entity bean concurrency support allows WebLogic Server to activate separate instance of a read-only bean for each transaction that needs concurrent access to that bean. This will eliminate the need for exclusive locking in the EJB Container and allow concurrent requests that access the same bean to proceed in parallel. See ReadOnly Concurrency Strategy for more information on read-only entity bean caching.

Combined Caching Support

Combined caching support allows you to configure a single cache for use with multiple entity beans. This will help solve usability and performance problems. Previously, you were required to configure a separate cache for each entity bean that was part of an application. See Combined Caching with Entity Beans for more information on combined caching.

Relationship Caching Support

Relationship caching support will improve entity bean performance by loading related entity beans into a cache and avoid multiple queries by issuing a join query for the related beans. See Combined Caching with Entity Beans for more information on relationship caching.

EJB Links Support

EJB links support allows you to link EJB references declared in one application component to an enterprise bean contained in the same J2EE application. See Using EJB Links for more information on EJB links.

Bulk Insert Support

Bulk insert support increases the performance of container managed persistence (CMP) bean creation by enabling the EJB container to perform multiple database inserts for CMP beans in one SQL statement. This feature allows the container to avoid multiple database inserts. See Database Insert Support for more information on this feature.

EJB Developer Tools

BEA provides several tools you can use to help you create and configure EJBs.

ANT Tasks to Create Skeleton Deployment Descriptors

You can use the WebLogic ANT utilities to create skeleton deployment descriptors. These utilities are Java classes shipped with your WebLogic Server distribution. The ANT task looks at a directory containing an EJB and creates deployment descriptors based on the files it finds in the ejb.jar file. Because the ANT utility does not have information about all of the desired configurations and mappings for your EJB, the skeleton deployment descriptors the utility creates are incomplete. After the utility creates the skeleton deployment descriptors, you can use a text editor, an XML editor, or the EJB Deployment Descriptor Editor in the Administration Console to edit the deployment descriptors and complete the configuration of your EJB.

For more information on using ANT utilities to create deployment descriptors, see Packaging Enterprise JavaBeans .

WebLogic Builder

WebLogic Builder is a development tools that provides a visual environment for you to edit an application's deployment descriptor XML files. You can use WebLogic Builder's interface to view these XML files as you edit them, but you will not need to make textual edits to the XML files. For instructions on how to use the WebLogic Builder tool, see WebLogic Builder.

EJBGen

EJBGen is an Enterprise JavaBeans 2.0 code generator. You can annotate your Bean class file with javadoc tags and then use EJBGen to generate the Remote and Home classes and the deployment descriptor files for an EJB application. For more information on EJBGen and a list of the supported javadoc tags, see EJBGen.

weblogic.Deployer

The weblogic.Deployer command-line utility is new in WebLogic Server 7.0 and replaces the deprecated weblogic.deploy utility. The weblogic.Deployer utility allows your to initiate deployment from the command line, a shell script, or any automated environment other than Java.

For instructions on using weblogic.Deployer and a list of the commands, see Deploying Using weblogic.Deployer.

WebLogic EJB Deployment Descriptor Editor

The WebLogic Server Administration Console has an integrated EJB deployment descriptor editor. You must create at least a skeleton of the following deployment descriptor files that you add to the ejb.jar file before using this integrated editor:

- ejb-jar.xml

- weblogic-ejb-jar.xml

- weblogic-cmp-rdbms-jar.xml

For more information, see Specifying and Editing the EJB Deployment Descriptors.

XML Editor

The XML editor is a simple, user-friendly tool from Ensemble for creating and editing XML files. It can validate XML code according to a specified DTD or XML Schema. You can use the XML editor on Windows or Solaris machines and download it from the Dev2Dev Online.