Part I Development Tasks and Tools
1. Setting Up a Development Environment
3. Using Ant with Enterprise Server
Part II Developing Applications and Application Components
7. Using the Java Persistence API
8. Developing Web Applications
9. Using Enterprise JavaBeans Technology
10. Using Container-Managed Persistence
Enterprise Server Support for CMP
The Mapping Deployment Descriptor File
Automatic Primary Key Generation
Fixed Length CHAR Primary Keys
Automatic Database Schema Capture
Using the capture-schema Utility
Version Column Consistency Checking
Configuring Queries for 1.1 Finders
CMP Restrictions and Optimizations
Restrictions on Remote Interfaces
No Support for lock-when-loaded on Sybase
Set RECURSIVE_TRIGGERS to false on MSSQL
13. Developing Lifecycle Listeners
Part III Using Services and APIs
14. Using the JDBC API for Database Access
15. Using the Transaction Service
16. Using the Java Naming and Directory Interface
The automatic schema generation feature provided in the Enterprise Server defines database tables based on the fields in entity beans and the relationships between the fields. This insulates developers from many of the database related aspects of development, allowing them to focus on entity bean development. The resulting schema is usable as-is or can be given to a database administrator for tuning with respect to performance, security, and so on.
This section addresses the following topics:
Note - Automatic schema generation is supported on an all-or-none basis: it expects that no tables exist in the database before it is executed. It is not intended to be used as a tool to generate extra tables or constraints.
Deployment won't fail if all tables are not created, and undeployment won't fail if not all tables are dropped. This is done to allow you to investigate the problem and fix it manually. You should not rely on the partially created database schema to be correct for running the application.
CMP supports a set of JDBC data types that are used in mapping Java data fields to SQL types. Supported JDBC data types are as follows: BIGINT, BIT, BLOB, CHAR, CLOB, DATE, DECIMAL, DOUBLE, FLOAT, INTEGER, NUMERIC, REAL, SMALLINT, TIME, TIMESTAMP, TINYINT, VARCHAR.
The following table contains the mappings of Java types to JDBC types when automatic mapping is used.
|
Note - Java types assigned to CMP fields must be restricted to Java primitive types, Java Serializable types, java.util.Date, java.sql.Date, java.sql.Time, or java.sql.Timestamp. An entity bean local interface type (or a collection of such) can be the type of a CMR field.
The following table contains the mappings of JDBC types to database vendor-specific types
when automatic mapping is used. For a list of the JDBC drivers currently
supported by the Enterprise Server, see the Sun GlassFish Enterprise Server v3 Release Notes. For configurations of supported and
other drivers, see
Configuration Specifics for JDBC Drivers in Sun GlassFish Enterprise Server v3 Administration Guide.
|
Deployment descriptor elements or asadmin command line options can control automatic schema generation by the following:
Creating tables during deployment
Dropping tables during undeployment
Dropping and creating tables during redeployment
Specifying the database vendor
Specifying that table names are unique
Specifying type mappings for individual CMP fields
Note - Before using these options, make sure you have a properly configured CMP resource.
See Configuring the CMP Resource.
For a read-only bean, do not create the database schema during deployment. Instead,
work with your database administrator to populate the data into the tables. See
Using Read-Only Beans.
Automatic schema generation is not supported for beans with version column consistency checking. Instead,
work with your database administrator to create the schema and add the required
triggers. See Version Column Consistency Checking.
The following optional data subelements of the cmp-resource element in the sun-ejb-jar.xml
file control the automatic creation of database tables at deployment. For more information about
the cmp-resource element, see cmp-resource in Sun GlassFish Enterprise Server v3 Application Deployment Guide and
Configuring the CMP Resource.
|
The following options of the asadmin deploy or asadmin deploydir command control the automatic creation of database tables at deployment.
|
If one or more of the beans in the module are manually mapped and you use any of the asadmin deploy or asadmin deploydir options, the deployment is not harmed in any way, but the options have no effect, and a warning is written to the server log.
The following options of the asadmin undeploy command control the automatic removal of database tables at undeployment.
|
For more information about the asadmin deploy, asadmin deploydir, and asadmin undeploy commands, see the Sun GlassFish Enterprise Server v3 Reference Manual.
When command line and sun-ejb-jar.xml options are both specified, the asadmin options take precedence.
The Ant tasks sun-appserv-deploy and sun-appserv-undeploy are equivalent to asadmin deploy and asadmin undeploy,
respectively. These Ant tasks also override the sun-ejb-jar.xml options. For details, see Chapter 3, Using Ant with Enterprise Server.