IBM


13.3.3 Defining data sources for entity beans

The entity beans in the Plants by WebSphere application are container-managed (CMP) EJBs. The EJB container handles the persistence of the EJB attributes in the underlying persistent store. You must specify which data store to use. This is done by binding an EJB module or an individual EJB to a data source. If you bind the EJB module to a data source, all EJBs in that module use the same data source for persistence. If you specify the data source at the EJB level, then this data source is used instead.

For the Plants by WebSphere application, the data source is bound at the EJB module level. The data source configured for the EJB must match the data source configured in the WebSphere environment. The JNDI name for this data source is eis/jdbc/PlantsByWebSphereDataSource_CMP. When a data source is defined in WebSphere, it can be marked as for use by container-manager persistence. If this option is selected the data source is then also mapped into the JNDI name space with a name like this.

To bind the Plants by WebSphere EJB module to this data source, follow these steps:

1. In the EJB Deployment Descriptor for the PlantsByWebSphereEJB module (see Figure 13-9), click the Overview tab.

2. In the Overview tab, scroll down and find the WebSphere bindings section, as in Figure 13-11.

Figure 13-11 Specifying the default CMP data source for the EJB module

Check the following fields:

New in V6.1: The embedded Cloudscape has a Cloudscape v10.1.x code base, referred to as Derby. Derby is a product of the Apache Software Foundation (ASF) open source relational database project. The new Cloudscape includes Derby without any modification to the underlying source code. Learn more about Derby code at the Apache Derby Web site:

http://db.apache.org/derby/

Backend ID

In EJB 2.x, mapping and schema files make up a back end for EJB 2.x projects. The Plants by WebSphere sample ships with a Cloudscape back end defined. Leave this for now, though in Creating a new database mapping and schema, we will create a new back end for DB2 and change this binding to point it.

JNDI name

Enter eis/jdbc/PlantsByWebSphereDataSource_CMP in the JNDI name field. This is the value the application uses to access the database. Note that this is the same, regardless of which back-end ID is used.

Container authorization type

Select Per_Connection_Factory for the Container authorization type.

3. Save the deployment descriptor.

Tip: An EJB JAR can contain database mappings and EJB deployment code for multiple databases. Because we imported the source code for the Plants by WebSphere sample, there is currently no deployed code, but we will generate it for DB2 UDB. You can set which back-end ID will be used at run time in the WebSphere bindings section. This choice can also be overridden at deployment time.


Redbooks ibm.com/redbooks

Next