@ejbgen:cmp-field Annotation

In a CMP entity bean, marks a virtual container-managed persistence (CMP) field.

Scope

Method tag for a CMP entity bean.

Syntax

@ejbgen:cmp-field

column="tableColumnName"

[column-type="OracleClob/OracleBlob"]

[exclude-from-value-object="True/False"]

[group-names="GroupName"]

[ordering-number="0...N"]

[primkey-field="True/False"]

[read-only-in-value-object="True/False"]

[table-name="TableName"]

Attributes

column

Required. Specifies the column in a database table to which this CMP field will be mapped.

column-type

Optional. Specify OracleClob or OracleBlob to map the CMP field to these database column types. When you use this field, you must declare the CMP field to either be a byte array or a class that implements the Serializable interface. If you want to serialize a byte array that is mapped to an OracleBlob, you must set the serialize-byte-array-to-oracle-blob attribute of the ejbgen:compatibility tag to true (default is false).

exclude-from-value-object

Optional. Specify true if you don't want this field to be included in the auto-generated value object (data transfer object) class. When left unspecified, this attribute defaults to false. For more information, see @ejbgen:file-generation Annotation.

group-names

Optional. This attribute defines how CMP fields of an entity bean are stored in memory. CMP fields and CMR fields that have the same group-name attribute specified are stored together. When this property is not used, all CMP fields and CMR fields are stored together in memory. Breaking up the memory signature into two or more groups can improve performance. For more details, see Accelerating Entity Bean Data Access.

ordering-number

Optional. Specify a number to enforce where this field will appear relative to other fields in signatures and constructors of generated compound primary key and value object (data transfer object) classes. In order for this ordering to work, all CMR and CMP fields must have this attribute set with a distinct numeric value. See the remark below.

primkey-field

Optional. Sets whether this field is the primary key field, or part of the compound primary key. The default is false.

read-only-in-value-object

Optional. Specify True if you want this field to be read-only in a generated value object class.

table-name

Optional. Specify the table(s) where this field should be mapped to. If the table-name is not specified, the CMP field is mapped to the table specified in the ejbgen:entity tag. You can also use this attribute to map primary key fields to multiple tables within the same database. For more information, see the example below.

Remarks

The following comments apply to this tag's use:


Multiple Table Mapping Example

The following example demonstrates the use of the table-name property. The MultipleTablesBean entity bean by default maps to the table OneTable as defined in the ejbgen:entity tag. The DefaultTable_field CMP field has no table-name property on its ejbgen:cmp-field tag and therefore maps to this table. The OtherTable_field CMP field has the table-name property set to OtherTable and therefore maps to the table OtherTable. The setMultipleTables_ID primary key field is set to both tables. Only primary keys can map to multiple tables:

/**
 * @ejbgen:entity prim-key-class="java.lang.Integer" 
 *   ejb-name="MT"
 *   data-source-name="cgSampleDataSource"
 *   table-name="OneTable"
 *   abstract-schema-name = "Divided"
 * ...
 */
public abstract class MultipleTablesBean extends GenericEntityBean implements EntityBean
{

    /**
     * @ejbgen:cmp-field column="DefaultTable_field"
     * @ejbgen:local-method
     */
    public abstract String getDefaultTable_field();

    /**
     * @ejbgen:local-method
     */
    public abstract void setDefaultTable_field(String arg);

    /**
     * @ejbgen:cmp-field table-name="OtherTable" column="OtherTable_field"
     * @ejbgen:local-method
     */
    public abstract String getOtherTable_field();

    /**
     * @ejbgen:local-method
     */
    public abstract void setOtherTable_field(String arg);

    /**
     * @ejbgen:cmp-field table-name="OneTable, OtherTable" primkey-field="true" column="Divided_ID, Divided_ID"
     * @ejbgen:local-method
     */
    public abstract Integer getMultipleTables_ID();

    /**
     * @ejbgen:local-method
     */
    public abstract void setMultipleTables_ID(Integer arg);



    public java.lang.Integer ejbCreate(java.lang.Integer MultipleTables_ID, java.lang.String OtherTable_field, java.lang.String DefaultTable_field)
    {
      setMultipleTables_ID(MultipleTables_ID);
      setOtherTable_field(OtherTable_field);
      setDefaultTable_field(DefaultTable_field);

      return null; // FIXME return PK value 
    }

    public void ejbPostCreate(java.lang.Integer MultipleTables_ID, java.lang.String OtherTable_field, java.lang.String DefaultTable_field)
    {
    }
}

Related Topics

How Do I: Define a Container-Managed Persistence (CMP) Field?

Accelerating Entity Bean Data Access

@ejbgen:entity Annotation

@ejbgen:file-generation Annotation

@ejbgen:cmr-field Annotation

ejbgen:compatibility Annotation