Entity Bean Configuration
Resin 2.1

Reference Guide
EJB Reference Guide

EJBServer
JNDI
Entity Config
Relation Config
Session Config
Resin-EJB Config
SQL mapping
Transaction Config
Message Config
EJB-QL
xdoclet
Config Summary
Burlap
JMS
CORBA/IIOP
Index
JNDI
EJB Reference Guide
Relation Config

Entity beans are the most common and correspond to database tables. Session beans are used to group business methods for certain applications.

Resin-CMP specific configuration is described on a separate page.

<ejb-jar>
  <enterprise-beans>
    <entity>
      <ejb-name>students</ejb-name>

      <ejb-class>example.StudentBean</ejb-class>

      <local-home>example.StudentHome</local-home>
      <local>example.Student</local>
      ...
    </entity>
  </enterprise-beans>
</ejb-jar>
abstract-schema-nameAbstract name of the database table that stores the fields of this CMP bean
cmp-fieldDefines one of the bean's fields to be managed by Resin-CMP
ejb-classDefines the bean's implementation class
ejb-nameThe name of the bean
field-nameSpecifies the field name for a cmp-field definition
homeDefines the remote home interface of the bean
localDefines the local interface for bean instances
local-homeDefines the local interface of the bean factory
method-intfSpecifies which interface a method description applies to
method-nameSpecifies the method name for a query-method
method-paramSpecifies a method parameter for a query-method
method-paramsSpecifies the method parameters for a query-method
persistence-typeDetermines whether Resin-CMP or the Bean Programmer is responsible for storing bean state in the database
prim-key-classThe Java Class type of the primary key field
primkey-fieldName of the entity bean's field that serves as the primary key
querySpecifies a query for a select or finder method
query-methodSpecifies the findXXX ejbSelectXXX method for a query a query
reentrantDefines whether the bean allows reentrant calls to the entity
remoteDefines the remote interface of the bean
result-type-mappingSpecifies whether a query result returns local or remote interfaces

Entity Bean Configuration

abstract-schema-name

Abstract name of the database table that stores the fields of this CMP bean. The abstract-schema-name is always used in EJB queries. It's the default name for the database table, although this can be overridden by sql-table.

The abstract-schema-name is optional. If unspecified, it defaults to the ejb-name.

cmp-field

Defines one of the bean's fields to be managed by Resin-CMP. Since Resin-CMP will introspect the cmp-fields from the classes, the cmp-field is optional.

cmp-fields are either Java primitives or serializable types, i.e. values in a database table. Relations between beans are configured in the relations section.

ElementMeaning
field-namethe field name
sql-columnthe SQL column name

The SQL name is generated automatically from the cmp-field (or the getter method.) The getter method getMyField corresponds to the cmp-field myField and the SQL column my_field. An EJB-QL query, always uses the cmp-field name, e.g. myField.

The cmp-field can specify the SQL column name using sql-column.

student.ejb
<entity>
  <abstract-schema-name>students</abstract-schema-name>
  <sql-table>student_table</sql-table>
  ...
  <cmp-field>
    <field-name>id</field-name>
    <sql-column>student_id</sql-column>
  </cmp-field>
  <cmp-field>
    <field-name>name</field-name>
    <sql-column>user_name</sql-column>
  </cmp-field>
  ...
</entity>

The above descriptor would expect the following schema:

student.sql
CREATE TABLE student_table (
  student_id INTEGER AUTO_INCREMENT,
  user_name VARCHAR(255),

  PRIMARY KEY(student_id)
);

ejb-class

Defines the bean's implementation class.

Each entity bean must specify an implementation class which implements the bean's methods. CMP entity beans will leave the container-managed fields abstract, while session beans and CMP entity beans must define all methods.

<ejb-jar>
  <enterprise-beans>
    <entity>
      <ejb-name>students</ejb-name>

      <ejb-class>example.StudentBean</ejb-class>

      <local-home>example.StudentHome</local-home>
      <local>example.Student</local>
      ...     
    </entity>
  </enterprise-beans>
</ejb-jar>

ejb-name

The name of the bean. The value of ejb-name is used to find the bean in JNDI and as the default schema name for CMP beans.

field-name

Specifies the field name for a cmp-field definition. The field-name is the bean name for the Java getter method. So the field-name for getFoo is foo.

home

Defines the remote home interface of the bean. The remote home lets clients on different machines use the bean, using some remote protocol like Burlap, Hessian, or CORBA/IIOP. Beans may have both a local home and a remote home and the home methods may expose different methods.

The remote home contains factory methods like find and create and also global bean methods which do not depend on the bean instance.

The remote home interface must extend javax.ejb.EJBHome.

<ejb-jar>
  <enterprise-beans>
    <entity>
      <ejb-name>students</ejb-name>
      <home>example.StudentRemoteHome</home>
      <remote>example.StudentRemote</remote>
      <local-home>example.StudentHome</local-home>
      <local>example.StudentRemote</local>
      ...
    </entity>
  </enterprise-beans>
</ejb-jar>

local

Defines the local interface for bean instances. Clients within the same JVM use the local interface to call bean methods.

The local interface must extend javax.ejb.EJBLocalObject. Entity beans using container managed persistence (CMP) must define a local interface. For BMP (bean managed persistence) beans, the local interface is optional.

<ejb-jar>
  <enterprise-beans>
    <entity>
      <ejb-name>students</ejb-name>
      <ejb-class>example.StudentBean</ejb-class>

      <local-home>example.StudentHome</local-home>
      <local>example.Student</local>
      ...
    </entity>
  </enterprise-beans>
</ejb-jar>

local-home

Defines the local interface of the bean factory. Clients within the same JVM use the local home to call bean factory methods.

The local home interface must extend javax.ejb.EJBLocalHome. Entity beans using container managed persistence (CMP) must define a local interface. For BMP (bean managed persistence) beans, the local interface is optional.

<ejb-jar>
  <enterprise-beans>
    <entity>
      <ejb-name>students</ejb-name>
      <local-home>example.StudentHome</local-home>
      <local>example.Student</local>
      ...
    </entity>
  </enterprise-beans>
</ejb-jar>

method-intf

Specifies which interface a method description applies to.

Because beans may have both remote and local interfaces, it is sometimes necessary to distinguish between the local and remote interfaces when specifying method names.

  • Home - the remote home interface
  • Remote - the remote object interface
  • LocalHome - the local home interface
  • Local - the local object interface

method-name

Specifies the method name for a query-method.

method-params

Specifies the method parameters for a query-method.

method-params ::= (method-param*)

method-param

Specifies a method parameter for a query-method.

persistence-type

Determines whether Resin-CMP or the Bean Programmer is responsible for storing bean state in the database. Container persistence is generally recommended because it simplifies maintenance and lets Resin-CMP cache the database more effectively.

This is the switch to turn on/off Container Managed Persistance. You need to set this to Container if you want to take advantags of Resin-CMP's automatic persistance feature.

The only two values allowed are Container and Bean. The values are case-sensitive.

<ejb-jar>
  <enterprise-beans>
    <entity>
      <ejb-name>students</ejb-name>
      ...     
      <persistence-type>Container</persistence-type>
      ...
    </;entity>
  </;enterprise-beans>
</;ejb-jar>

prim-key-class

The Java Class type of the primary key field.

Every entity bean must have a primary key which is used to find the bean from the database. Resin-CMP needs to know the name of Java class that the primary key will be mapped to; a simple choice is java.lang.String. Note that you can also specify a simple int as the primkey-field, even though it is a simple datatype and not a Java class:

<ejb-jar>
  <enterprise-beans>
    <entity>
      ...     
      <prim-key-class>int</prim-key-class>
      ...
    </;entity>
  </;enterprise-beans>
</;ejb-jar>

primkey-field

Name of the entity bean's field that serves as the primary key.

A bean bean with a compound key will not have a primkey-field because the compound key class specifies the primary key fields.

query

Specifies a query for a select or finder method.

A query is associated with a method of the bean's home interface (finder method) or implementation class (select method). It is formulated in EJB-QL, EJB 2.0's query language. The query element contains two required nested elements:

Element NamePurpose
queryContaining element for a query.
query-methodSpecifies the associated method.
method-nameThe name of the method for the query.
method-paramsParameters for the query.
ejb-qlThe actual query that selects beans or CMP objects.

query-method has two sub-elements; method-name and method-params.

  • method-name contains the name of the associated method, which as per EJB 2.0 spec must begin with 'find' or 'ejbSelect'.
  • method-params contains one method-param element per parameter of the associated query method. method-param elements state the type of the parameter they describe.

ejb-ql is described in the EJB-QL reference guide .

Sample <query> block
  <query>
    <query-method>
      <method-name>ejbSelectByName</method-name>
      <method-params>
        <method-param>java.lang.String</method-param>
      </method-params>
    </query-method>
    <ejb-ql>
      <![CDATA[SELECT student
               FROM students student,
               WHERE student.name=?1]]>
    </ejb-ql>
  </query>

query ::= (query-method,
           result-type-mapping?,
           ejb-ql)

query-method

Specifies the findXXX ejbSelectXXX method for a query a query.

query-method has two sub-elements; method-name and method-params.

  • method-name contains the name of the associated method, which as per EJB 2.0 spec must begin with 'find' or 'ejbSelect'.
  • method-params contains one method-param element per parameter of the associated query method. method-param elements state the type of the parameter they describe.

Sample query-method
<query-method>
  <method-name>ejbSelectByName</method-name>
  <method-params>
    <method-param>java.lang.String</method-param>
  </method-params>
</query-method>

Resin-CMP allows a shortcut where the query-method is a Java-style method declaration, making the deployment descriptor more readable.

query-method short form
<query-method>ejbSelectByName(java.lang.String)&/query-method>

query-method ::= (ejb-name,
                  method-intf?,
                  method-name,
                  method-params?)

method-params ::= (method-param*)

reentrant

Defines whether the bean allows reentrant calls to the entity. The values 'True' or 'False' are case-sensitive.

An example of reentrancy, or loopback, is when a Student entity bean calls a House entity bean, which then calls the Student bean. The initial call to the House bean 'looped back' to the Student.

remote

Defines the remote interface of the bean. The remote interface will extend javax.ejb.EJBObject. Clients from different web-apps or even different servers may use the remote interface.

<ejb-jar>
  <enterprise-beans>
    <entity>
      <ejb-name>students</ejb-name>
      <ejb-class>example.StudentBean</ejb-class>

      <home>example.StudentRemoteHome</home>
      <remote>example.StudentRemote</remote>
      ...
    </;entity>
  </;enterprise-beans>
</;ejb-jar>

result-type-mapping

Specifies whether a query result returns local or remote interfaces.

Default: Local

Formal Definition

entity ::= (ejb-name,
            home?,
            remote?,
            local-home?,
            local?,
            ejb-class,
            persistence-type,
            prim-key-class,
            reentrant,
            abstract-schema-name,
            cmp-field*,
            primkey-field?,
            query*)

cmp-field ::= (field-name)

query ::= (query-method,
           result-type-mapping?,
           ejb-ql)

query-method ::= (ejb-name,
                  method-intf?,
                  method-name,
                  method-params?)

method-params ::= (method-param*)


JNDI
EJB Reference Guide
Relation Config
Copyright © 1998-2006 Caucho Technology, Inc. All rights reserved.
Resin® is a registered trademark, and HardCoretm and Quercustm are trademarks of Caucho Technology, Inc.