Before you begin, you must complete Exercise 1.3: Adding entity beans to class diagrams.
Exercise 1.4 teaches you how to create the database mapping files for CloudscapeTM. It explains the files created and their use. In this module, you will do these tasks:
Next, you will map the entity beans to a relational database. Mapping involves creating database definition files for the tables that will be used to store the entity bean's fields. Generally, each bean uses a different table. Fields in the bean represent columns in the table. Key fields in the bean correspond to primary keys in the database table.
Database mapping results in a set of files that are discussed later. These files are packaged with the EJB. They are also used by an administrator to create the database tables when putting the EJB application into production. The database mapping files are dependent on the database type.
You can create a set of database mapping files for one or several database types, which are listed below.
This approach, creating database definitions from existing entity beans, is called top-down mapping. The reverse process, bottom-up mapping, is also provided, where you create entity beans from existing database tables. Meet-in-the-middle mapping is also available, for use when you have existing enterprise beans and existing database tables. See Mapping enterprise beans to database tables for more information.
To create mapping files for Cloudscape, follow these steps:
Cloudscape V5.1
as the Target Database. UMLEJB
as the Database name.NULLID
as the Schema name.
In the Project Explorer view, under EJB Projects > UML EJB tutorial > ejbModule > META-INF > backends, you will see the folder CLOUDSCAPE_V51_1 which contains the mapping files listed below. Another view of the mapping relationships can be found in EJB Projects > UML EJB tutorial > Deployment Descriptor > Maps directory. You can locate the newly mapped table in the Project Explorer view by selecting the table on the class diagram, right-clicking and selecting Navigate > Show in > Data Definition View.
Map.mapxmi
This XML file defines the relationships between the CMP fields in the beans and the database schema. Double-click the file in the Project Explorer view to see a visual representation.
Table.ddl
This is the data definition file. It contains the SQL table creation statements and other table definitions. It is used to create the actual database that will be used to persist the EJB application data on the test or production server.
UMLEJB_NULLID_AUTHOR.tblxmi
This XML file has a name derived from the database name, the schema name and the table name. It uses the XMI tag library to define entries for the database, schema, columns and data types. This particular file defines the Author bean table.
UMLEJB_NULLID_BOOK.tblxmi
This XML file defines the Book bean table.
UMLEJB_NULLID_Author_Book.tblxmi
This XML file defines the relationships between the Author and Book beans.
UMLEJB_NULLID.schxmi
This XML file defines the schema, with pointers to the other XMI-encoded files.
UMLEJB.dbxmi
This XML file defines the database, with pointers to the other XMI-encoded files.
Now you are ready to begin Exercise 1.5: Finishing the EJB creation process.