Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 814edc0b45717979020a13ff372d0d856f26e64e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii" />
<meta http-equiv="Content-Style-Type" content="text/css" />
<meta http-equiv="Content-Script-Type" content="text/javascript" />
<title>Creating a JPA entity</title>
<meta name="copyright" content="Copyright (c) 2000, 2009 oracle . All rights reserved. This program and the accompanying materials are made available under the terms of the Eclipse Public License v1.0 which accompanies this distribution, and is available at http://www.eclipse.org/legal/epl-v10.html. Contributors: Oracle - initial API and implementation" />
<meta name="generator" content="Oracle DARB XHTML Converter (Mode = ohj/ohw) - Version 1.0.11" />
<meta name="date" content="2013-04-05T12:21:25Z" />
<meta name="robots" content="noarchive" />
<meta name="doctitle" content="Creating a JPA entity" />
<meta name="relnum" content="Release 3.3" />
<meta name="partnum" content="Release 3.3" />
<link rel="copyright" href="dcommon/html/cpyr.htm" title="Copyright" type="text/html" />
<link rel="stylesheet" href="dcommon/css/blafdoc.css" title="Oracle BLAFDoc" type="text/css" />
</head>
<body>
<p><a id="BABFBJBG" name="BABFBJBG"></a></p>
<div class="sect1"><!-- infolevel="all" infotype="General" -->
<h1><a id="sthref80" name="sthref80"></a>Creating a JPA entity</h1>
<p><a id="sthref81" name="sthref81"></a>Use this procedure to create a JPA entity with the <a href="ref_create_jpa_entity_wizard.htm#CIAGGGDF">Create JPA Entity wizard</a>:</p>
<ol>
<li>
<p>From the Navigator or Project Explorer, select the JPA project and then <span class="bold">File &gt; New &gt; Other</span>. The Select a Wizard dialog appears.</p>
<div class="figure"><a id="sthref82" name="sthref82"></a>
<p class="titleinfigure">Selecting the Create a JPA Entity Wizard</p>
<img src="img/select_a_wizard_entity.png" alt="The Select a Wizard dialog with Entity selected." title="The Select a Wizard dialog with Entity selected." /><br /></div>
<!-- class="figure" -->
<div align="center">
<div class="inftblnotealso"><br />
<table class="NoteAlso oac_no_warn" summary="" cellpadding="3" cellspacing="0">
<tbody>
<tr>
<td align="left">
<p class="notep1">Tip:</p>
<p>You can also select the JPA perspective and then select <span class="bold">File &gt; New &gt; JPA Entity</span>.</p>
</td>
</tr>
</tbody>
</table>
<br /></div>
<!-- class="inftblnotealso" --></div>
</li>
<li>
<p>Select <span class="bold">JPA &gt; JPA Entity</span> and then click <span class="bold">Next</span>. The <a href="ref_EntityClassPage.htm#CIAFEIGF">Entity Class page</a> appears.</p>
<div class="figure"><a id="sthref83" name="sthref83"></a>
<p class="titleinfigure"><a id="sthref84" name="sthref84"></a>The Entity Class Page</p>
<img src="img/create_jpa_entity_wizard.png" alt="The Entity Class page of the Create a JPA Entity wizard." title="The Entity Class page of the Create a JPA Entity wizard." /><br /></div>
<!-- class="figure" -->
<p>Complete the fields on the <a href="ref_EntityClassPage.htm#CIAFEIGF">Entity Class page</a> as follows:</p>
<ul>
<li>
<p>Select the JPA project in the <span class="bold">Project</span> field.</p>
</li>
<li>
<p>In the <span class="bold">Source Folder</span> field, select, or enter, the location of the JPA project's <code>src</code> folder.</p>
</li>
<li>
<p>Select, or enter, the name of the class package for this entity in the <span class="bold">Java Package</span> field.</p>
</li>
<li>
<p>Enter the name of the Java class in the <span class="bold">Class name</span> field.</p>
</li>
<li>
<p>If needed, enter, or select a superclass.</p>
</li>
<li>
<p>If needed, complete the Inheritance section as follows (these properties are optional):</p>
<ul>
<li>
<p>Accept the <span class="bold">Entity</span> option (the default) to create a Java class with the <code>@Entity</code> option.</p>
</li>
<li>
<p>Alternatively, select <a href="tasks006.htm#BABDAGCI">Mapped superclass</a> (if you defined a super class).</p>
</li>
<li>
<p>Select <span class="bold">Inheritance</span> and then select one of the JSR 220 inheritance mapping strategies (SINGLE_TABLE, TABLE_PER_CLASS, JOINED).</p>
</li>
<li>
<p>Select <span class="bold">Add to entity mappings in XML</span> to create XML mappings in <code>orm.xml</code>, rather than annotations.</p>
</li>
</ul>
</li>
</ul>
</li>
<li>
<p>Click <span class="bold">Next</span> to proceed to the <a href="ref_EntityPropertiesPage.htm#CIADECIA">Entity Properties page</a> where you define the persistent fields for the entity.</p>
<div class="figure"><a id="sthref85" name="sthref85"></a>
<p class="titleinfigure"><a id="sthref86" name="sthref86"></a>The Entity Properties Page</p>
<img src="img/create_jpa_fields.png" alt="The Entity Properties page of the Create JPA Entity wizard." title="The Entity Properties page of the Create JPA Entity wizard." /><br /></div>
<!-- class="figure" -->
<p>Alternatively, click <span class="bold">Finish</span> to complete the entity.</p>
</li>
<li>
<p>Complete the page as follows:</p>
<ol>
<li>
<p>If needed, enter a new name for the entity. Doing so results in adding a <code>name</code> attribute to the <code>@Entity</code> notation (<code>@Entity(name="EntityName")</code>).</p>
</li>
<li>
<p>Accept <span class="bold">Use default</span> (the default setting) to use the default value for the name of the mapped table. Entering a different name results in adding the <code>@Table</code> notation with its <code>name</code> attribute defined as the new table (<code>@Table(name="TableName")</code>).</p>
<div align="center">
<div class="inftblnote"><br />
<table class="Note oac_no_warn" summary="" cellpadding="3" cellspacing="0">
<tbody>
<tr>
<td align="left">
<p class="notep1">Note:</p>
<p>The Entity Name-related options are not available if you selected <a href="tasks006.htm#BABDAGCI">Mapped superclass</a> on the <a href="ref_EntityClassPage.htm#CIAFEIGF">Entity Class page</a></p>
</td>
</tr>
</tbody>
</table>
<br /></div>
<!-- class="inftblnote" --></div>
</li>
<li>
<p>Add persistence fields to the entity by clicking <span class="bold">Add</span>. The Entity Fields dialog appears.</p>
<div class="figure"><a id="sthref87" name="sthref87"></a>
<p class="titleinfigure">The Entity Fields Dialog</p>
<img src="img/jpa_wizard_create_fields.png" alt="The Entity Fields dialog." title="The Entity Fields dialog." /><br /></div>
<!-- class="figure" --></li>
<li>
<p>Select a persistence type from the <span class="bold">Type</span> list. You can retrieve additional types using the <span class="bold">Browse</span> function.</p>
</li>
<li>
<p>Enter the field name and then click <span class="bold">OK</span>. Repeat this procedure for each field.</p>
</li>
<li>
<p>If needed, select <span class="bold">Key</span> to designate the field as a primary key.</p>
</li>
<li>
<p>Select either the <span class="bold">Field-based</span> access type (the default) or <span class="bold">Property-based</span> access type.</p>
</li>
</ol>
</li>
<li>
<p>Click <span class="bold">Finish</span>. Eclipse adds the entity to your project.</p>
</li>
</ol>
<a id="sthref88" name="sthref88"></a>
<p class="subhead2">Related reference</p>
<ul>
<li>
<p><a href="ref_new_jpa_project_wizard.htm#CACBJGBG">Create New JPA Project wizard</a></p>
</li>
<li>
<p><a href="ref_persistence_perspective.htm#BABIFBDB">JPA Development perspective</a></p>
</li>
<li>
<p><a href="ref_create_jpa_entity_wizard.htm#CIAGGGDF">Create JPA Entity wizard</a></p>
</li>
</ul>
<a id="sthref89" name="sthref89"></a>
<p class="subhead2">Related tasks</p>
<ul>
<li>
<p><a href="task_add_persistence.htm#BABHICAI">Adding persistence to a class</a></p>
</li>
</ul>
<a id="sthref90" name="sthref90"></a>
<p class="subhead2">Related concepts</p>
<ul>
<li>
<p><a href="concept_persistence.htm#BABCAHIC">Understanding Java persistence</a></p>
</li>
<li>
<p><a href="concepts002.htm#CHDHAGIH">The persistence.xml file</a></p>
</li>
</ul>
</div>
<!-- class="sect1" -->
<!-- Start Footer -->
<div class="footer">
<table class="simple oac_no_warn" summary="" cellspacing="0" cellpadding="0" width="100%">
<col width="86%" />
<col width="*" />
<tr>
<td align="left"><span class="copyrightlogo">Copyright&nbsp;&copy;&nbsp;2011, 2013,&nbsp;Oracle&nbsp;and/or&nbsp;its&nbsp;affiliates.&nbsp;All&nbsp;rights&nbsp;reserved.</span><br />
<a href="dcommon/html/cpyr.htm"><span class="copyrightlogo">Legal Notices</span></a></td>
</tr>
</table>
</div>
<!-- class="footer" -->
</body>
</html>

Back to the top