Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: b69c13e56141f1615fe5ac2957636fc9206930dc (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
<!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>
<!-- Run date = January 22, 2008 9:11:18 -->
<meta name="OAC_IGNORE_SKIP_NAV" content="true" />
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii" />
<title>Specifying entity inheritance</title>
<meta http-equiv="Content-Style-Type" content="text/css" />
<meta http-equiv="Content-Script-Type" content="text/javascript" />
<meta name="generator" content="Oracle DARB XHTML Converter (Mode = ohj/ohw) - Version 5.0" />
<meta name="date" content="2005-07-10T12:57:20+08:00" />
<meta name="robots" content="noarchive" />
<meta name="doctitle" content="Specifying entity inheritance" />
<meta name="relnum" content="M5 - Release 2.0.0" />
<meta name="partnum" content="" />
<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" />
<link rel="start" href="../../index.htm" title="Home" type="text/html" />
<link rel="contents" href="toc.htm" title="Contents" type="text/html" />
</head>
<body>
<p><a id="CIHCCCJD" name="CIHCCCJD"></a></p>
<div class="sect1"><!-- infolevel="all" infotype="General" -->
<h1>Specifying entity inheritance</h1>
<p><a id="sthref100" name="sthref100"></a><a id="sthref101" name="sthref101"></a>An entity may inherit properties from other entities. You can specify a specific strategy to use for inheritance.</p>
<p>Use this procedure to specify inheritance (<code>@Inheritance)</code> for an existing entity (<code>@Entity</code>):</p>
<ol start="1">
<li>
<p>Select the entity in the <span class="gui-object-title">Package Explorer</span>.</p>
</li>
<li>
<p>In the <span class="gui-object-title">JPA Details</span> view, select the <span class="gui-object-action">Inheritance</span> information.</p>
<div class="figure"><a id="sthref102" name="sthref102"></a>
<p class="titleinfigure">Specifying Inheritance</p>
<img src="img/inheritance_tab.png" alt="Selecting the Inheritance area on the JPA Details view." title="Selecting the Inheritance area on the JPA Details view." /><br /></div>
<!-- class="figure" --></li>
<li>
<p>In the <span class="bold">Strategy</span> list, select one of the following the inheritance strategies:</p>
<ul>
<li>
<p>A single table (default)</p>
</li>
<li>
<p>Joined table</p>
</li>
<li>
<p>One table per class</p>
</li>
</ul>
</li>
<li>
<p>Use the following table to complete the remaining fields on the tab. See <a href="reference006.htm#CACFHGHE">"Inheritance information"</a> for additional details.</p>
<div class="inftblruleinformal">
<table class="RuleInformal" title="This table describes the options on the Persistence Properties view, Inheritance tab." summary="This table describes the options on the Persistence Properties view, Inheritance tab." dir="ltr" border="1" width="100%" frame="border" rules="all" cellpadding="3" cellspacing="0">
<thead>
<tr align="left" valign="top">
<th align="left" valign="bottom" id="r1c1-t3">Property</th>
<th align="left" valign="bottom" id="r1c2-t3">Description</th>
<th align="left" valign="bottom" id="r1c3-t3">Default</th>
</tr>
</thead>
<tbody>
<tr align="left" valign="top">
<td align="left" id="r2c1-t3" headers="r1c1-t3"><a id="sthref103" name="sthref103"></a><a id="sthref104" name="sthref104"></a>Discriminator Column</td>
<td align="left" headers="r2c1-t3 r1c2-t3">Name of the discriminator column when using a <span class="bold">Single</span> or <span class="bold">Joined</span> inheritance strategy.
<p>This field corresponds to the <code>@DiscriminatorColumn</code> annotation.</p>
</td>
<td align="left" headers="r2c1-t3 r1c3-t3"><br /></td>
</tr>
<tr align="left" valign="top">
<td align="left" id="r3c1-t3" headers="r1c1-t3">Discriminator Type</td>
<td align="left" headers="r3c1-t3 r1c2-t3">Set the discriminator type to <code>Char</code> or <code>Integer</code> (instead of its default: <code>String</code>). The <span class="bold">Discriminator Value</span> must conform to this type.</td>
<td align="left" headers="r3c1-t3 r1c3-t3">String</td>
</tr>
<tr align="left" valign="top">
<td align="left" id="r4c1-t3" headers="r1c1-t3"><a id="sthref105" name="sthref105"></a><a id="sthref106" name="sthref106"></a>Discriminator Value</td>
<td align="left" headers="r4c1-t3 r1c2-t3">Specify the discriminator value used to differentiate an entity in this inheritance hierarchy. The value must conform to the specified <span class="bold">Discriminator Type</span>.
<p>This field corresponds to the <code>@DiscriminatorValue</code> annotation.</p>
</td>
<td align="left" headers="r4c1-t3 r1c3-t3"><br /></td>
</tr>
<tr align="left" valign="top">
<td align="left" id="r5c1-t3" headers="r1c1-t3">Override Default</td>
<td align="left" headers="r5c1-t3 r1c2-t3">Use this field to specify custom primary key join columns.
<p>This field corresponds to the <code>@PrimaryKeyJoinClumn</code> annotation.</p>
</td>
<td align="left" headers="r5c1-t3 r1c3-t3"><br /></td>
</tr>
</tbody>
</table>
<br /></div>
<!-- class="inftblruleinformal" --></li>
</ol>
<p>Eclipse adds the following annotations the entity field:</p>
<pre xml:space="preserve" class="oac_no_warn">
@Inheritance(strategy=InheritanceType.<span class="italic">&lt;INHERITANCE_STRATEGY&gt;</span>)
@DiscriminatorColumn(name="<span class="italic">&lt;DISCRIMINATOR_COLUMN&gt;</span>",
    discriminatorType=<span class="italic">&lt;DISCRIMINATOR_TYPE&gt;</span>)
@DiscriminatorValue(value-"<span class="italic">&lt;DISCRIMINATOR_VALUE&gt;</span>")
@PrimaryKeyJoinColumn(name="<span class="italic">&lt;JOIN_COLUMN_NAME&gt;</span>", 
    referencedColumnName = "<span class="italic">&lt;REFERENCED_COLUMN_NAME&gt;</span>")

</pre>
<p><a id="sthref107" name="sthref107"></a><a id="sthref108" name="sthref108"></a><a id="sthref109" name="sthref109"></a>The following figures illustrates the different inheritance strategies.</p>
<div class="figure"><a id="sthref110" name="sthref110"></a>
<p class="titleinfigure">Single Table Inheritance</p>
<img src="img/inheritance_single.png" alt="This figure illustrates entity inheritance in a single table." title="This figure illustrates entity inheritance in a single table." /><br /></div>
<!-- class="figure" -->
<div class="figure"><a id="sthref111" name="sthref111"></a>
<p class="titleinfigure"><a id="sthref112" name="sthref112"></a><a id="sthref113" name="sthref113"></a>Joined Table Inheritance</p>
<img src="img/inheritance_join.png" alt="This figure illustrates a joined subclass inheritance strategy." title="This figure illustrates a joined subclass inheritance strategy." /><br /></div>
<!-- class="figure" -->
<br />
<p>&nbsp;</p>
<img src="img/ngrelt.png" alt="Related task" title="Related task" /><br />
<br />
<a href="task_add_persistence.htm#BABHICAI">Adding persistence to a class</a>
<p>&nbsp;</p>
<img src="img/ngrelc.png" alt="Related concept" title="Related concept" /><br />
<br />
<a href="concept_persistence.htm#BABCAHIC">Understanding Java persistence</a><br /></div>
<!-- class="sect1" -->
<!-- Start Footer -->
<div class="footer">
<table class="simple oac_no_warn" summary="" cellspacing="0" cellpadding="0" width="100%">
<tr>
<td align="left" width="86%"><a href="dcommon/html/cpyr.htm"><span class="copyrightlogo">Copyright&nbsp;&copy;&nbsp;2006, 2008,&nbsp;Oracle.&nbsp;All&nbsp;rights&nbsp;reserved.</span></a></td>
</tr>
</table>
</div>
<!-- class="footer" -->
</body>
</html>

Back to the top