Skip to main content
blob: d4e124b0efeaf206e7c801186d297ce94dacb851 (plain) (tree)






























<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
<html xmlns="" xml:lang="en" lang="en">
<!-- Run date = July 23, 2008 8:59:45 -->
<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="Release 2.0" />
<meta name="copyright" content="Copyright (c) 2000, 2008 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 Contributors: Oracle - initial API and implementation" />
<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" />
<!-- start-->
<!-- contents -->
<p><a id="CIHCCCJD" name="CIHCCCJD"></a></p>
<div class="sect1"><!-- infolevel="all" infotype="General" -->
<h1>Specifying entity inheritance</h1>
<p><a id="sthref80" name="sthref80"></a><a id="sthref81" name="sthref81"></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">
<p>Select the entity in the <span class="gui-object-title">Package Explorer</span>.</p>
<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="sthref82" name="sthref82"></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>
<p>In the <span class="bold">Strategy</span> list, select one of the following the inheritance strategies:</p>
<p>A single table (default)</p>
<p>Joined table</p>
<p>One table per class</p>
<p>Use the following table to complete the remaining fields on the tab. See <a href="reference012.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">
<tr align="left" valign="top">
<th align="left" valign="bottom" id="r1c1-t14">Property</th>
<th align="left" valign="bottom" id="r1c2-t14">Description</th>
<th align="left" valign="bottom" id="r1c3-t14">Default</th>
<tr align="left" valign="top">
<td align="left" id="r2c1-t14" headers="r1c1-t14"><a id="sthref83" name="sthref83"></a><a id="sthref84" name="sthref84"></a>Discriminator Column</td>
<td align="left" headers="r2c1-t14 r1c2-t14">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 align="left" headers="r2c1-t14 r1c3-t14"><br /></td>
<tr align="left" valign="top">
<td align="left" id="r3c1-t14" headers="r1c1-t14">Discriminator Type</td>
<td align="left" headers="r3c1-t14 r1c2-t14">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-t14 r1c3-t14">String</td>
<tr align="left" valign="top">
<td align="left" id="r4c1-t14" headers="r1c1-t14"><a id="sthref85" name="sthref85"></a><a id="sthref86" name="sthref86"></a>Discriminator Value</td>
<td align="left" headers="r4c1-t14 r1c2-t14">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 align="left" headers="r4c1-t14 r1c3-t14"><br /></td>
<tr align="left" valign="top">
<td align="left" id="r5c1-t14" headers="r1c1-t14">Override Default</td>
<td align="left" headers="r5c1-t14 r1c2-t14">Use this field to specify custom primary key join columns.
<p>This field corresponds to the <code>@PrimaryKeyJoinClumn</code> annotation.</p>
<td align="left" headers="r5c1-t14 r1c3-t14"><br /></td>
<br /></div>
<!-- class="inftblruleinformal" --></li>
<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>")

<p><a id="sthref87" name="sthref87"></a><a id="sthref88" name="sthref88"></a><a id="sthref89" name="sthref89"></a>The following figures illustrates the different inheritance strategies.</p>
<div class="figure"><a id="sthref90" name="sthref90"></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="sthref91" name="sthref91"></a>
<p class="titleinfigure"><a id="sthref92" name="sthref92"></a><a id="sthref93" name="sthref93"></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 />
<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>
<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%">
<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>
<!-- class="footer" -->

Back to the top