CMP EntityBeans

|  |  |  | FAQ CMP EntityBeans |

Main
Welcome!
Download
Mailing Lists
The Team

Users
Quickstart
Hello World!
CMP Example
CMP Guide
Deploy
Startup
Validation
Configuration
Support
Request Feature
FAQ

Servers
Local Server
Remote Server
Tomcat

Integrators
Why OpenEJB
Overview
Design
Specification
Presentation

Developers
Custom Services
Release Plan
Source Code
SourceForge

CMP EntityBeans

- What engine does OpenEJB use for CMP persistence?
- What is the format for the CMP mapping files?
- How are primary keys created for CMP EntityBeans?
- How do I map my CMP finder methods?
- Does OpenEJB support EJB-QL?
- What is the syntax of OQL?

## What engine does OpenEJB use for CMP persistence?

OpenEJB uses Castor JDO for CMP persistence. The CMP config files are all Castor controlled files (www.castor.org). At the moment, most of the real juicy CMP configuration file information is at the Castor site. There is no difference between configuring a CMP EntityBean in OpenEJB than with any other Castor controlled java object, so anything you learn about Castor's config files will be applicable.

## What is the format for the CMP mapping files?

The Castor JDO mapping file provides a mechanism for binding a CMP EntityBean deployed in OpenEJB to a relational database model. This is usually referred to as object-to-relational mapping (O/R mapping). O/R mapping bridges the gap between an object model and a relational model.

The format of these files is documented here

## How are primary keys created for CMP EntityBeans?

The KeyGenerator is responsible for creating the primary key of the records that are inserted by Castor. More information on that here

## How do I map my CMP finder methods?

You can map your finder methods in the openejb-jar.xml that is created by the deploy tool. Just grab the openejb-jar.xml file from the META-INF directory of your jar and add a 'query' declaration like the one below for all the CMP entities that need them.

After the deployer is run for the first time, using your favourite editor edit openejb-jar.xml file and add your finder select statement in openejb-jar.xml file.

Repackage your jar file.

If openejb is already running close currently running openejb instance by telnet localhost 4200 and issuing the stop command and restart openejb.

Test your program by calling Runit.sh .

Whenever deployer is run again for your current application, it will overwrite openejb-jar.xml file.

Say you had a home interface with the following finder method...

    package org.acme.employee;

    ...

    public interface EmployeeHome extends EJBHome{

      ...

      public Employee findByLastName( String lastName )
             throws RemoteException, FinderException;

    }

... then that would require a 'query' declaration in your openejb-jar.xml file like this one ...

META-INF/openejb-jar.xml

    <ejb-deployment ...
      <query>
        <query-method>
          <method-name>findByLastName</method-name>
          <method-params>
            <method-param>java.lang.String</method-param>
          </method-params>
        </query-method>
        <object-ql>
        SELECT o FROM org.acme.employee.EmployeeBean o WHERE o.lastname = $1
        </object-ql>
      </query>
    </ejb-deployment>

The 'query' element goes inside an 'ejb-deployment' element, right under any 'resource-link' elements that may be there already.

## Does OpenEJB support EJB-QL?

No, EJB-QL is an EJB 2.0 CMP feature, so that syntax won't work with OpenEJB as the 2.0 spec isn't yet supported. However...

We do support OQL (Object Query Language), which is functionally identical.

## What is the syntax of OQL?

The syntax of the query statement must be Object Query Language (OQL) compatible as described in the ODMG 3.0 specification section 4.12. OQL is nearly identical to EJB QL, so converting CMP beans from 1.1 to 2.0 will be very easy.

OQL itself is parsed by our persistence engine Castor, see this document for more details on writing OQL statements for use with OpenEJB and Castor. More information on that here

Java, EJB, JDBC, JNDI, JTA, Sun, Sun Microsystems are trademarks or registered trademarks of Sun Microsystems, Inc. in the United States and in other countries. XML, XML Schema, XSLT and related standards are trademarks or registered trademarks of MIT, INRIA, Keio or others, and a product of the World Wide Web Consortium. All other product names mentioned herein are trademarks of their respective owners.