Part I Development Tasks and Tools
1. Setting Up a Development Environment
Part II Developing Applications and Application Components
6. Using the Java Persistence API
7. Developing Web Applications
8. Using Enterprise JavaBeans Technology
9. Using Container-Managed Persistence
GlassFish 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
12. Developing Lifecycle Listeners
13. Developing OSGi-enabled Java EE Applications
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 GlassFish 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.
The following topics are addressed here:
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.
Table 9-1 Java Type to JDBC Type Mappings for CMP
|
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 GlassFish Server, see the Oracle GlassFish Server 3.1-3.1.1 Release Notes. For configurations of supported and other drivers, see Configuration Specifics for JDBC Drivers in Oracle GlassFish Server 3.1 Administration Guide.
Table 9-2 Mappings of JDBC Types to Database Vendor Specific Types for CMP
|
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 glassfish-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 Oracle GlassFish Server 3.1 Application Deployment Guide and Configuring the CMP Resource.
Table 9-3 The glassfish-ejb-jar.xml Generation Elements
|
The following options of the asadmin deploy or asadmin deploydir command control the automatic creation of database tables at deployment.
Table 9-4 The asadmin deploy and asadmin deploydir Generation Options for CMP
|
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.
Table 9-5 The asadmin undeploy Generation Options for CMP
|
For more information about the asadmin deploy, asadmin deploydir, and asadmin undeploy commands, see the Oracle GlassFish Server 3.1-3.1.1 Reference Manual.
When command line and glassfish-ejb-jar.xml options are both specified, the asadmin options take precedence.