Show TOC Start of Content Area

Function documentation Object/Relational Mapping Rules  Locate the document in its SAP Library structure

Use

The following rules for the O/R mapping are required by the EJB Container when you deploy container-managed entity beans on the J2EE Engine. The O/R mapping verification checks whether these rules are fulfilled. If you create your O/R mapping manually, make sure you fulfill all the requirements in this document.

Caution

If the following requirements are not fulfilled, the EJB Container cannot guarantee that the abstract schema will work correctly.

Integration

The O/R mapping created with the SAP NetWeaver Developer Studio meets all requirements listed below. If you have modified it, we recommend that you switch on the O/R mapping verification. For more information, see Verifying the Object/Relational Mapping.

Features

Enterprise Bean Restrictions

·        Each enterprise bean from the abstract schema is stored in a separate table

cmp-field Restrictions

·        A cmp-field, which is not dependent-value, is mapped to a single column

·        The acceptable JDBC types for a column depend on the Java type of the corresponding cmp-field:

Java and JDBC Types

Java Type

Acceptable JDBC Types

Default JDBC Type

java.lang.String

VARCHAR, CHAR4, LONGVARCHAR3, CLOB3

VARCHAR

byte[]

VARBINARY, BINARY4, LONGVARBINARY3, BLOB3

VARBINARY

java.lang.Byte[]

VARBINARY, BINARY4, LONGVARBINARY3, BLOB3

VARBINARY

short

SMALLINT

SMALLINT

java.lang.Short

SMALLINT

SMALLINT

int

INTEGER

INTEGER

java.lang.Integer

INTEGER

INTEGER

long

BIGINT

BIGINT

java.lang.Long

BIGINT

BIGINT

float

REAL

REAL

java.lang.Float

REAL

REAL

double

DOUBLE, FLOAT4

DOUBLE

java.lang.Double

DOUBLE, FLOAT4

DOUBLE

java.math.BigDecimal

DECIMAL, NUMERIC4

DECIMAL

java.util.Date

TIMESTAMP

TIMESTAMP

java.sql.Date

DATE

DATE

java.sql.Time

TIME

TIME

java.sql.Timestamp

TIMESTAMP

TIMESTAMP

java.sql.Clob

CLOB3

CLOB3

java.sql.Blob

BLOB3

BLOB3

boolean

SMALLINT1

SMALLINT1

java.lang.Boolean

SMALLINT1

SMALLINT1

byte

SMALLINT2

SMALLINT2

java.lang.Byte

SMALLINT2

SMALLINT2

java.io.Reader

VARCHAR2

VARCHAR2

java.io.InputStream

VARBINARY2

VARBINARY2

...

       1.      The Common JDBC default mapping is BIT; however, boolean/java.lang.Boolean is not fully supported by Common JDBC. SMALLINT is the preferred mapping for the EJB Container.

       2.      No Common JDBC default mapping exists; type/class is not fully supported by Common JDBC.

       3.      LOGVARBINARY, LONGVARCHAR, BLOB, and CLOB are not permitted in WHERE-clauses, ORDER BY-clauses, and SELECT DISTINCT statements.

       4.      Not fully supported JDBC type.

 

·        cmp-fields with char and java.lang.Character Java types are not supported. Use java.lang.String with length 1 instead.

·        cmp-fields with java.lang.String or byte[] Java types at runtime must not have an empty value. This may lead to unpredictable database behavior.

·        If a cmp-field represents a date type and will be involved in a QL query, its Java type must be java.util.Date.

·        A cmp-field, which is dependent-value, can be mapped to:

¡        A single column of type java.sql.Types.BLOB.

The value of the cmp-field is serialized to a byte array by using the standard Java serialization mechanism.

¡        A set of columns

This is possible only if the dependent-value class has an empty constructor and all its fields, which are described in the <dv-column> element, are public.

Each public field of the dependent-value class that is described in the <dv-column> element in persistent.xml is mapped to one of the columns in the set. The columns in the set are part of the bean’s table, as are the other cmp-fields of the bean. These columns cannot be defined in a separate table. Only the fields described in the <dv-column> element will be stored in the database. The type of these fields can be:

§         A standard Java type – it is stored in its corresponding column. The type of the column must be one of the acceptable JDBC types for that Java type.

§         A serializable Java type – the field is serialized and stored in its corresponding column in the set. The JDBC type of this column must be java.sql.Types.BLOB.

·        A column is defined as primary key only if the column is part of the O/R mapping of a primary key cmp-field

·        If an enterprise bean has unknown primary key, then a default primary key cmp-field must be used. Its name is “ejb_pk”. Therefore, it is not allowed other non-primary key cmp-fields to have the same name. The O/R mapping of this additional cmp-field must be described in persistent.xml – that is, if you automatically generate persistent.xml (for example, by using the shell language commands or the SAP NetWeaver Developer Studio), the system will generate that O/R mapping. For more information, see Creating Primary Keys. The JDBC type of the corresponding column must be java.sql.Types.BIGINT and this column must be the only primary key column in the database table.

cmr-field Restrictions

·        Relationships are realized using references between primary key column(s) and foreign key column(s), or logical foreign key column(s). A column is called “a logical foreign key” if it is a column that contains the values of the referenced table’s primary key column, but is not declared as a foreign key. From now on, when we refer to a “foreign key” column, we will mean both a standard foreign key and a logical foreign key.

·        One or more different foreign key columns are defined for each relationship. If there are N relationships between two beans, then there must be N mappings between primary keys and foreign key columns.

·        The JDBC type of a foreign key column must be the same as the JDBC type of the referenced primary key column.

·        A unique key column cannot be used as part of a foreign key. This means that you are not allowed to define a foreign key column as a unique or primary key column, too.

One-to-One Relationship

·        The foreign key columns are columns in one of the two tables that participate in this relationship.

One-to-Many Relationship

·        The foreign key columns are columns in the table of the bean whose multiplicity in this relationship is Many.

Many-to-Many Relationship

·        It is mandatory that you use a helper table. It should contain columns that are foreign key columns referencing the primary key columns of the two tables to which the beans participating in this relationship are mapped. The columns should have the same JDBC type as the primary key columns of the referenced tables.

Check Limitations

The system is not able to detect the following mistakes in the O/R mapping:

·        A column is described as a logical foreign key but is a real foreign key

·        A column is a unique key and is defined as a foreign key

 

 

End of Content Area