Chapter 8 Creating J2EE Applications for BEA WebLogic


Automatic Table Creation

WebLogic Server supports a feature that allows you to automatically create tables based on the descriptions in the deployment files and the bean class, if the table does not already exist. Tables are created for all beans and relationship join tables, if the relationships in the .jar files have joins. You explicitly turn on this feature by defining it in the deployment descriptors for each RDBMS deployment, for all beans in the .jar file.

A best attempt is made to create the new table. However, if based on the descriptions in the deployment files, the field cannot be successfully mapped to an appropriate column type in the database, the TABLE CREATION fails, an error will be thrown, and the table must be created by hand.

This feature is not recommended for use in a production environment. It is better suited for use during the development phase for design and prototype work. A production environment may require the use of more precise table schema definitions, for example the declaration of foreign key constraints.

Steps To define this feature:

  1. In the weblogic-cmp-rdbms-jar.xml file, set the create-default-dbms-tables element to True to explicitly turn on automatic table creation for all beans in the .jar file.
  2. Use the following syntax:

<create-default-dbms-tables>True
	</create-default-dbms-tables>

Because this feature may not successfully map every Java field type to your target database, the following list is provided to give you an idea of the type of mapping you can expect to see.

Java Type DBMS Column Type
Boolean INTEGER
Byte INTEGER
Char CHAR
Double DOUBLE PRECISION
float FLOAT
int INTEGER
long INTEGER
Short INTEGER
java.lang.string VARCHAR (150)
java.lang.BigDecimal DECIMAL (38, 19)
java.lang.Boolean INTEGER
java.lang.Byte INTEGER
java.lang.Character CHAR (1)
java.lang.Double DOUBLE PRECISION
java.lang.Float FLOAT
java.lang.Integer INTEGER
java.lang.Long INTEGER
java.lang.Short INTEGER
java.sql.Date DATE
java.sql.Time DATE
java.sql.Timestamp DATETIME
byte[ ] RAW (1000)
Any serializable Class that is not a valid SQL type RAW (1000)

 


Copyright (C) 2005. Sybase Inc. All rights reserved.