user manual
Chapter 14: Entity Beans and CMP 1.1 in Borland Enterprise Server 147
Setting Properties
Automatic table mapping
The Borland EJB container has the capability to automatically map Java types
defined in the enterprise bean code to database table types. However, while it
may create these tables automatically, it does not necessarily use the most
optimal mapping approach. In fact, automatically generating these mappings
and tables is more of a convenience for developers.
The Borland-generated tables are not optimized for performance. Often, they
overuse database resources. For example, the container maps a Java String
field to the corresponding SQL VARCHAR type. However, the mapping is not
sensitive to the actual length of the Java field, and so it maps all string fields to
the maximum VARCHAR length. Thus, it might map a two-character Java String to
a VARCHAR(2000) column.
In a production situation, it is preferable for database administrators (DBA) to
create the tables and do the type mapping. The DBA can override the default
mappings and produce a table optimized for performance and use of database
resources.
While all relational databases implement SQL types, there may be significant
variations in how they implement these types. Even when they support SQL
types with the same semantics, they may use different names to identify these
types. For example, Oracle implements a Java boolean as aNUMBER(1,0), while
Sybase implements it as a BIT and DB2 implements it as a SMALLINT.
When the Borland EJB Container creates the database tables for your
enterprise beans, it automatically maps entity bean fields and database table
columns. The container must know how to properly specify the SQL types so
that it can correctly create the tables in each supported database. As a result,
the EJB Container maps some Java types differently, depending on the
database in use. The following table shows the mapping for Oracle, Sybase/
MSSQL, and DB2:
java.sql.Timestamp TIMESTAMP
java.util.Date TIMESTAMP
java.io.Serializable VARBINARY
Java types Oracle Sybase/MSSQL DB2
boolean/Boolean NUMBER(1,0) BIT SMALLINT
byte/Byte NUMBER(3,0) TINYINT SMALLINT
char/Character CHAR(1) CHAR(1) CHAR(1)
double/Double NUMBER FLOAT FLOAT
float/Float NUMBER REAL REAL
int/Integer NUMBER(10,0) INT INTEGER
long/Long NUMBER(19,0) NUMERIC(19,0) BIGINT
short/Short NUMBER(5,0) SMALLINT SMALLINT
Java type JDBC SQL type










