Developing enterprise beans

One of two development scenarios is typically used with WebSphere Application Server. The first is command-line using Ant, Make, Maven or similar tools. The second is an IDE-based development and build environment. The steps in this article focus on development without an IDE.

Before you begin

Design a J2EE application and the enterprise beans that it needs.
  • For general design information, see the topic Resources for learning.
  • Before developing entity beans with container-managed persistence (CMP), read the topic Concurrency control.
New or updated for this feature pack Design a Java Enterprise Edition (Java EE) application and the enterprise beans that it needs.
  • For general design information, see the topic, "Resources for learning."
  • Before developing entity beans with container-managed persistence (CMP), read the topic, "Concurrency control." Keep in mind that EJB 3.0 modules do not support CMP entity beans. You must continue to place CMP entity beans in your EJB 2.x-level modules.

About this task

The following is more information about the two basic approaches to selecting tools for developing enterprise beans:
  • You can use one of the available IDE tools that automatically generate significant parts of the enterprise bean code and contain integrated tools for packaging and testing enterprise beans. The Rational Application Developer product is the recommended IDE. For more information, see the documentation for that product.

    New or updated for this feature pack To use the assembly tools with EJB 3.0 modules, you need to add <WAS_HOME>/lib/j2ee.jar to the project's build path to resolve compilation dependencies on the new EJB 3.0 API classes. Code assist works once this is done. If you define a server (see J2EE Perspective), point the server to the WebSphere Application Server install directory. Before you create the project, the project automatically refers to <WAS_HOME>/lib/j2ee.jar. Be sure to create the server with the setting Run server with resources on Server.

    New or updated for this feature pack See the topic "Assembling EJB 3.0 modules" for more information on using the Application Server Toolkit to assemble EJB 3.0 modules.

  • If you have decided to develop enterprise beans without an IDE, you need at least an ASCII text editor. You can also use a Java development tool that does not support enterprise bean development. You can then use tools available in the Java Software Development Kit (SDK) and in this product to assemble, test, and deploy the beans.

    New or updated for this feature pack Like the assembly tool, a standard Java EE command-line build environment requires little some change to utilize the Feature Pack for EJB 3.0 capabilities. As with previous Java EE application development patterns, you must include the j2ee.jar file located in the <WAS_HOME>/lib/ directory on the compiler classpath. An example of a command-line build environment using Ant is located in the <WAS_HOME>/samples/src/TechSamp directory.

The following steps primarily support the second approach, development without an IDE.

Procedure

  1. If necessary, migrate any pre-existing code to the required version of the Enterprise JavaBeans (EJB) specification.

    New or updated for this feature pack Applications written to the EJB specification versions 1.1, 2.0, and 2.1 can run unchanged in the EJB 3.0 container.

  2. Write and compile the components of the enterprise bean.
    • New or updated for this feature pack At a minimum, a session bean developed with the EJB 3.0 specification requires a bean class and a business interface.
    • At a minimum, an EJB 1.1 session bean requires a bean class, a home interface, and a remote interface. An EJB 1.1 entity bean requires a bean class, a primary-key class, a home interface, and a remote interface.
    • At a minimum, an EJB 2.x session bean requires a bean class, a home or local home interface, and a remote or local interface. An EJB 2.x entity bean requires a bean class, a primary-key class, a remote home or local home interface, and a remote or local interface. The types of interfaces go together: If you implement a local interface, you must also define a local home interface.
      Note: Optionally, the primary-key class can be unknown. See unknown primary-key class for more information.
    • A message-driven bean requires only a bean class.
  3. For each entity bean, complete work to handle persistence operations.

    New or updated for this feature pack For the Feature Pack for EJB 3.0, consider using the Java Persistence API (JPA) specification to develop plain old Java Object (POJO) persistent entities. Review the topic "Java Persistence API" for more information. If you choose to develop entity beans to earlier EJB specifications, follow the steps below:

    • Create a database schema for the entity bean's persistent data.
      • For entity beans with CMP, you must store the bean's persistent data in one of the supported databases. The Application Server Toolkit automatically generates SQL code for creating database tables for CMP entity beans. If your CMP beans require complex database mappings, it is recommended that you use Rational Application Developer to generate code for the database tables.
      • For entity beans with bean-managed persistence (BMP), you can create the database and database table by using the database tools or use an existing database and database table.

      For more information on creating databases and database tables, review your database documentation.

    • (CMP entity beans for EJB 2.x only)

      Define finder queries with EJB Query Language (EJB QL).

      Define finder queries with EJB Query Language (EJB QL).

      With EJB QL, you define finders in terms of CMP fields and container-managed relationships, as follows:
      • Public finders are visible in the bean's home interface. Implemented in the bean class, they return only remote interfaces and collection types.
      • Private finders, expressed as SELECT statements, are used only within the bean class. They can return both local and remote interfaces, dependent values, other CMP field types, and collection types.
    • (CMP entity beans for EJB 1.1 only: an IBM extension) Create a finder helper interface for each CMP entity bean that contains specialized finder methods (other than the findByPrimaryKey method).
      The following logic is required for each finder method (other than the findByPrimaryKey method) contained in the home interface of an entity bean with CMP:
      • The logic must be defined in a public interface named NameBeanFinderHelper, where Name is the name of the enterprise bean, for example, AccountBeanFinderHelper.
      • The logic must be contained in a String constant named findMethodName WhereClause, where findMethodName is the name of the finder method. The String constant can contain zero or more question marks (?) that are replaced from left to right with the value of the finder method's arguments when that method is called.

What to do next

Assemble the beans in one or more EJB modules

New or updated for this feature pack Assemble the beans in one or more EJB 3.0 modules.




In this information ...


IBM Redbooks, demos, education, and more

(Index)

Use IBM Suggests to retrieve related content from ibm.com and beyond, identified for your convenience.

This feature requires Internet access.

Task topic Task topic    

Terms and conditions for information centers | Feedback

Last updatedLast updated: Aug 31, 2013 2:56:59 AM CDT
http://www14.software.ibm.com/webapp/wsbroker/redirect?version=pix&product=was-nd-dist&topic=tejbdvdp
File name: tejb_dvdp.html