Developing Your First Beans - Creating a CABIN Table in the Database
(Page 3 of 5 )
One of the primary jobs of a deployment tool is mapping entity beans to databases. In the case of the Cabin entity, we must map its id , name , deckLevel , shipId , and bedCount fields to some data source. Before proceeding with deployment, you need to set up a database and create a CABIN table. You can use the following standard SQL statement to create a CABIN table that will be consistent with the examples provided in this chapter:
create table CABIN
(
ID int primary key NOT NULL,
SHIP_ID int,
BED_COUNT int,
NAME char(30),
DECK_LEVEL int
)

Figure 4-2. titan.jar contents
This statement creates a CABIN table that has five columns corresponding to the container-managed fields in the Cabin class. Once the table is created and connectivity to the database is confirmed, you can proceed with the deployment process.
Alternatively, most if not all persistence provider implementations will support auto-generation of your database tables. For example, you can configure JBoss to create the tables for each entity bean when the application server boots and deploys its EJBs. Other application servers will have different mechanisms to do this.
Deploying the EJB JARDeployment is the process of reading the beans JAR file, changing or adding properties to the deployment descriptor, mapping the bean to the database, defining access control in the security domain, and generating any vendor-specific classes needed to support the bean in the EJB environment. Some EJB server products require you to use a set of deployment tools to deploy your EJBs to your application server. These tools may provide a graphical user interface or a set of command-line programs.
A deployment tool reads the JAR file and looks for annotated classes as well as any possible XML deployment descriptors so that it can determine which EJBs and entities are being deployed. In a graphical deployment wizard, the metadata of each EJB and entity is presented using a set of property sheets similar to those used in environments such as Visual Basic .NET, PowerBuilder, and JBuilder.
Some EJB servers, like JBoss, do not require any special vendor-generated classes, so there is no need for a deployment tool. JBoss, for instance, just requires you to put your ejb JAR in a deploy/ directory. The application server examines the JAR file at runtime when the server boots up to determine which EJB containers must be created and attached to the runtime.
Next: Creating a Client Application >>
More Java Articles
More By O'Reilly Media
|
This article is taken from chapter 4 of the book Enterprise JavaBeans 3.0 Fifth Edition, written by Richard Monson-Haefel and Bill Burke (O'Reilly, 2006; ISBN: 059600978X). Check it out today at your favorite bookstore. Buy this book now.
|
|