IBM WebSphere Application Server V6.1 Feature Pack for EJB 3.0
IBM® WebSphere® Application Server V6.1 Feature Pack for EJB 3.0 Enterprise Java™ Beans (EJB) 3.0 Overview
This presentation gives an overview of the WebSphere Application Server V6.1 Feature Pack for EJB 3.0.
Agenda
Agenda EJB 2.1 drawbacks Changes in EJB 3.0 Simplified programming model Metadata annotations Increased use of defaults Dependency injection New persistence framework Changes in WebSphere Application Server
This presentation will first describe some of the drawbacks of EJB 2.1 that provided the motivation for EJB 3.0. Then it will give an overview of the major changes in EJB 3.0, and some changes that were made in WebSphere Application Server itself.
EJB 2.1 drawbacks
EJB 2.1 drawbacks Section
This section describes some of the drawbacks in EJB 2.1.
EJB 2.1 drawbacks
EJB 2.1 drawbacks Overly complex for developers Several source files for each EJB XML deployment descriptors Throw and catch unnecessary exceptions Required callback methods often unused Testing challenges Some beans are abstract classes Require a container for testing
The EJB specification has often been criticized for being overly complex. For example, new developers are often confused about why it is necessary to create several different source files for each EJB. Similarly, you are required to implement several callback methods even if you do not use them, and handle exceptions that may be unnecessary. Deployment descriptors can also be difficult to understand, and can be a bottleneck in a team development environment, since only one person can be updating the deployment descriptor at a given time. EJB 2.1 applications also cannot be tested outside of a container, since some beans are abstract classes that are implemented by the container at runtime.
Changes in EJB 3.0
Changes in EJB 3.0 Section
This section will provide an overview of the changes introduced by the EJB 3.0 specification.
Goals of EJB 3.0
Goals of EJB 3.0 Make the simple things easy, while keeping the complex things possible Simplify development and usage Avoid invasiveness Utilize context appropriate defaults Only require actions when the default needs to be overridden
The main goal of EJB 3.0 is to simplify the programming model. The new specification aims to make it as easy as possible to implement simple things, while keeping complex things possible. In many cases this is accomplished by utilizing contextually appropriate default values, allowing you to override the defaults when needed. When it is possible for the container to figure something out, it will do so, rather than requiring a developer to provide unnecessary information. With this simplification, regular Java developers should be able to develop EJBs. That is, if you can write a plain-old Java object (POJO), you can write a business object.
Business logic simplification
Business logic simplification Plain-old Java object (POJO) style business logic Fewer source files Home interfaces are unnecessary Business interfaces are generated automatically No need to implement unnecessary callbacks No need to throw or catch unnecessary exceptions Optional deployment descriptors Dynamic deployment
Many changes have been made in EJB 3.0, in an effort to simplify the programming model. EJBs are now developed as plain-old Java objects, rather than their more complex predecessors. Home interfaces are unnecessary in most cases, and business interfaces can be generated automatically by the runtime, so there are far fewer source files to develop and maintain. Along the same line, you now only have to implement life cycle callback methods if you actually want to use them, and the specification no longer requires you to implement unused exceptions. Deployment descriptors are optional in EJB 3.0, because as you will see in this presentation, metadata can now be specified directly in your Java code, using annotations. EJB 3.0 containers also handle deployment dynamically, so you no longer have to manually deploy your EJBs.
Persistence in EJB 3.0
Persistence in EJB 3.0 Java Persistence API (JPA) is a standard persistence and object-relational mapping (ORM) framework for Java Part of the EJB 3.0 specification (JSR220) Represents relational data as plain-old Java objects (POJOs) RDB Entity Manager Client POJO POJO read update
The Java Persistence API, or JPA, is a new framework for Java object persistence and object-relational mapping that was introduced as a part of the EJB 3.0 specification. In JPA, relational data is represented using plain-old Java objects called “Entities”, rather than the more complex “Entity Beans” that are used in Container-Managed Persistence (CMP). JPA is considered both simpler and lighter-weight than CMP. The presentation titled “JPA overview” discusses JPA in more detail.
Annotations
Annotations EJB 3.0 leverages Java 5 annotations (JSR175) Metadata in code instead of deployment descriptor Can annotate classes, methods, or variables Compiled into the class file Basic examples: @Stateful denotes a stateful session bean @Stateless denotes a stateless session bean @MessageDriven denotes a message-driven bean
Java annotations were introduced in Java SE 5, under JSR175, and are widely used in EJB 3.0. Annotations are used to specify metadata directly in code, rather than in an XML deployment descriptor, and are compiled directly into your class file. For example, adding “@Stateful” before the name of a class defines it as a stateful session bean, and that no longer needs to be specified in a deployment descriptor. Similar annotations exist for Stateless Session Beans, Message-Driven beans, and JPA Entities. Annotations can be used to provide more complex information as well, as you can see in the presentation titled “EJB 3.0 code examples”.
XML deployment descriptors
XML deployment descriptors EJB 3.0 deployment descriptors are optional May be partially defined Default values used for undefined elements Override annotations if both are present Annotations and deployment descriptors are functionally equivalent Metadata can be defined equally by either method
EJB deployment descriptors can still be used in EJB 3.0, if you prefer to use them over annotations. Deployment descriptors can even be partial, if you want to provide some information using annotations, and keep other information in XML. Any values that are not specified will inherit intelligent default values. In the case that the same information is specified by both a Java annotation and the XML deployment descriptor, the data in the deployment descriptor will be used. With experience, you may find that you prefer using annotations for some things, and deployment descriptors for others. It is entirely up to you, as the two are functionally equivalent.
Dependency injection
Dependency injection Resource dependencies can be declared using annotations Inversion-of-control pattern eliminates boilerplate code and lets the container do the work No longer need to use factories to get objects from JNDI Examples: @EJB ShoppingCart myCart injects an EJB instance @Resource DataSource bankDS injects a Data Source object
EJB 3.0 also introduces annotations for injecting resource dependencies using the “Inversion of control” pattern. Rather than implement boilerplate code and use a factory to get an object, look it up in JNDI, and then cast or narrow it to make it useable, you now need only to use the @Resource annotation to inject a dependency. The examples shown on this slide illustrate how to inject an instance of an EJB using the @EJB annotation, and a data source using the @Resource annotation.
Interoperability with older EJBs
Interoperability with older EJBs EJB 1 and 2 beans are supported CMP beans should be packaged in a separate JAR file from EJB 3.0 beans To use an older bean from an EJB 3.0 bean: Look up the home interface and use the bean just as you would in EJB 2 To use an EJB 3.0 bean from an older bean: The EJB 3.0 bean must have a home interface, and a component (EJBObject/EJBLocalObject based) interface Look up the home interface and use the bean just as you would an older bean
The EJB 3.0 specification requires compatibility with earlier versions, so EJB 1 and 2 beans are still supported when the Feature Pack for EJB 3.0 is installed. You should package any CMP beans in a separate EJB JAR file from your EJB 3.0 beans. If you want to call an older EJB from an EJB 3.0 bean, you only need to look up the bean’s home interface, and use it exactly as you would in an EJB 2 bean. To call an EJB 3.0 bean from an older EJB, you need to create a home interface and a component interface for the EJB 3.0 bean, since they are expected by the older bean. Once you have created those interfaces, you can look up the home interface and call it exactly as you would call an older bean.
Changes in WebSphere Application Server
Changes in WebSphere Application Server Section
This section covers improvements to WebSphere Application Server when the Feature Pack for EJB 3.0 is installed.
WebSphere Application Server pain points
WebSphere Application Server pain points Too much “waiting around” Edit-compile-test cycle is too long Too much manual intervention Vendor-specific tools required for persistence mapping Manual packaging and transfer of client artifacts JNDI bindings must be assigned during assembly or installation Too much dependency on WebSphere Application Server and WebSphere-specific tools
It has often been said that the edit-compile-test cycle is too long when developing applications for WebSphere Application Server. The EJB deployment step had to occur each time you modified an application, and that can take a very long time, depending on application complexity. Vendor-specific tools were also required for persistence mapping. Another frequent pain point is that JNDI bindings had to be specified manually, either during application assembly or installation. There has also been a dependency on WebSphere Application Server or WebSphere-specific tools for some tasks, such as editing WebSphere-specific .xmi files.
WebSphere Application Server improvements
WebSphere Application Server improvements “Just in time” deployment and code generation EJBDeploy no longer required Container merges metadata from annotations and deployment descriptors Automatic binding and referencing by EJB container (optional)
When using EJB 3.0 applications on WebSphere Application Server, many of these pain points are resolved. The Feature Pack for EJB 3.0 provides “just in time” deployment and code generation, so the “EJBDeploy” step is no longer required. The container merges the metadata provided in annotations and deployment descriptors dynamically. Automatic binding is another capability that is provided by the Feature Pack. It automatically binds beans to both a short and long JNDI name, so that you do not have to provide bindings manually. The long-form binding is guaranteed to be unique. Consult the Information Center for more information on automatic binding. You can override the automatic bindings by providing your own bindings if you prefer.
Summary and references
Summary and references Section
This section will summarize the presentation, and list some resources for further information.
Summary
Summary EJB 3.0 is designed to simplify development of business logic Avoid invasiveness Utilize context appropriate defaults Only require actions when the default needs to be overridden Support for Java annotations or deployment descriptors Support for dependency injection JPA simplifies Java persistence and object-relational mapping Simpler and more lightweight than CMP in EJB 2
The EJB 3.0 specification is designed to make it faster and easier to develop your business logic. By introducing Java annotations for EJBs, dependency injection support, removing boilerplate code, and making use of intelligent defaults, EJB 3.0 provides a framework that enables anyone with Java skills to develop enterprise beans. The Java Persistence API is also a part of the EJB 3.0 specification, and provides a simple and lightweight framework for Java persistence and object-relational mapping. It is discussed in a separate presentation module in more detail.
EJB 3.0 and JPA resources
EJB 3.0 and JPA resources EJB 3.0 specification (JSR220) http://java.sun.com/products/ejb/docs.html Java 5 annotations http://java.sun.com/j2se/1.5.0/docs/guide/language/annotations.html Apache OpenJPA http://openjpa.apache.org/
This slide lists some resources where you can learn more about EJB 3.0 and JPA. You should also consult the Feature Pack for EJB 3.0 Information Center for more information.
Feedback
Feedback Your feedback is valuable You can help improve the quality of IBM Education Assistant content to better meet your needs by providing feedback. Did you find this module useful? Did it help you solve a problem or answer a question? Do you have suggestions for improvements? Click to send e-mail feedback: mailto:iea@us.ibm.com?subject=Feedback_about_WASv61_EJB3FP_EJB3Overview.ppt This module is also available in PDF format at: ../WASv61_EJB3FP_EJB3Overview.pdf
You can help improve the quality of IBM Education Assistant content by providing feedback.
Trademarks