5
* Copyright � 2007 Sun Microsystems, Inc. All rights reserved.
6
* Use is subject to license terms.
11
<title>Generating CMP Entity Beans from a Database</title>
12
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
13
<link rel="stylesheet" href="nbdocs://org.netbeans.modules.usersguide/org/netbeans/modules/usersguide/ide.css" type="text/css">
18
<h2>Generating CMP Entity Beans from a Database</h2>
19
<p><small><a href="#seealso">See Also</a></small></p>
20
<p>In addition to writing CMP <a href="../general/about_entity_beans.html">entity
21
beans</a> from scratch, you can also generate a set of CMP entity beans for
22
an existing database. You can generate CMP entity beans from an existing database
23
connection or from a database schema.</p>
25
<li>Make sure that you have access to the database source from which you want
26
to generate the entity beans:
28
<li>If you want to generate entity beans from an existing database connection,
29
make sure the database is running and you have
30
<a href="nbdocs://org.netbeans.modules.db/org/netbeans/modules/db/docs/connectdb.html">registered a connection</a>
31
to it in the Services window.</li>
32
<li>If you want to use a database schema, make sure the database schema
33
file exists in your project's <tt>conf</tt> folder.</li>
36
<li>Right-click the EJB module project node in the Projects window and choose
37
New > CMP Entity Beans from Database.</li>
38
<li>Select the database source:
40
<li><b>JDBC Connection.</b> The drop-down list displays all your registered database
41
connections. You can add a database connection by choosing Add Connection
42
from the drop-down list.</li>
43
<li><b>Database Schema.</b> The drop-down list displays all of the database schema
44
files in your project's <tt>conf</tt> folder. If your project does not
45
contain any database schema files, this option is disabled.</li>
48
<li>In the Location drop-down list, select the source root to which you want to add the enterprise beans .</li>
49
<li>In the Package drop-down list, select an existing package or type a new package name.</li>
50
<li>Specify whether to generate finder methods for all CMP fields. </li>
51
<li>Specify whether to add the CMP Fields and CMR fields to the local interfaces.</li>
53
<li>Select any table from the list on the left and click Add. Then click Finish. </li>
55
<p>When you generate entity beans from a database, the IDE does the following:</p>
57
<li>If creating the entity beans from a database connection, grabs the database
58
structure and stores it in a database schema file in your project's <tt>conf</tt>
60
<li>Creates an entity bean for each of the selected tables and any tables the selected
61
tables reference. A node for each entity bean is displayed in the project's
62
Enterprise Beans node. By default, the generated entity beans only have local
63
interfaces. Each entity bean contains a CMP field for each column in the table
64
and a CMR field for any column that references another table. </li>
65
<li>Configures any container-managed relationships in the EJB module's <tt>ejb-jar.xml</tt>
66
deployment descriptor. </li>
68
<p>If your project's target server is the Sun Java System Application Server/GlassFish, the IDE also
69
does the following:</p>
71
<li>Creates a <tt>sun-cmp-mappings.xml</tt> file under the Configuration Files
72
node that contains CMP mapping information for the entity beans. The IDE
73
maps all CMP fields to the correct columns in the database. You can view and
74
edit CMP mappings by double-clicking <tt>sun-ejb-jar.xml</tt> or <tt>sun-cmp-mappings.xml</tt>,
75
and then clicking the XML tab to edit the file in the XML editor.</li>
76
<li>Prepares a connection object and JDBC resources for the project which are
77
configured on the server when you run or deploy the project. You can view
78
and edit these resources in the <tt>sun-resources.xml</tt> file under the Server Resources node in the Projects window.</li>
81
<li>If you are deploying to the JBoss or WebLogic application servers, you have
82
to write your server-specific deployment descriptors and configure the required
83
server resources yourself.</li>
86
<dt><a name="seealso">See Also</a></dt>
87
<dd><a href="create_ejb_project.html">Creating an EJB Module Project</a></dd>
88
<dd><a href="../../enterprise/general/ent_app_creating.html">Creating an Enterprise Application Project</a></dd>
89
<dd><a href="nbdocs://org.netbeans.modules.visualweb.ravehelp.rave_nbpack/org/netbeans/modules/visualweb/ravehelp/rave_nbpack/docs/web/create/about/about_create_webapps.html">About Creating Web Applications</a></dd>
90
<dd><a href="call_ejb.html">Creating an Enterprise Bean</a> </dd>
91
<dd><a href="../general/about_entity_beans.html">About EJB 2.1 Entity Beans</a> </dd>
92
<dd><a href="nbdocs://org.netbeans.modules.dbschema/org/netbeans/modules/dbschema/docs/dbschema.html">Creating a Database Schema</a> </dd>
96
<small> <a href="../../credits.html">Legal Notices</a></small>
97
<table cellpadding="50" border="0">
98
<tr><td> </td></tr>
b'\\ No newline at end of file'