10.12.2012 Views

The Java EE 5 Tutorial (PDF) - Oracle Software Downloads

The Java EE 5 Tutorial (PDF) - Oracle Software Downloads

The Java EE 5 Tutorial (PDF) - Oracle Software Downloads

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Mapped superclasses are not queryable, and can’t be used in EntityManager or Query<br />

operations. You must use entity subclasses of the mapped superclass in EntityManager or<br />

Query operations. Mapped superclasses can’t be targets of entity relationships. Mapped<br />

superclasses can be abstract or concrete.<br />

Mapped superclasses do not have any corresponding tables in the underlying datastore. Entities<br />

that inherit from the mapped superclass define the table mappings. For instance, in the code<br />

sample above the underlying tables would be FULLTIM<strong>EE</strong>MPLOY<strong>EE</strong> and PARTTIM<strong>EE</strong>MPLOY<strong>EE</strong>, but<br />

there is no EMPLOY<strong>EE</strong> table.<br />

Non-Entity Superclasses<br />

Entities may have non-entity superclasses, and these superclasses can be either abstract or<br />

concrete. <strong>The</strong> state of non-entity superclasses is non-persistent, and any state inherited from<br />

the non-entity superclass by an entity class is non-persistent. Non-entity superclasses may not<br />

be used in EntityManager or Query operations. Any mapping or relationship annotations in<br />

non-entity superclasses are ignored.<br />

Entity Inheritance Mapping Strategies<br />

You can configure how the <strong>Java</strong> Persistence provider maps inherited entities to the underlying<br />

datastore by decorating the root class of the hierarchy with the<br />

javax.persistence.Inheritance annotation. <strong>The</strong>re are three mapping strategies that are<br />

used to map the entity data to the underlying database:<br />

■ A single table per class hierarchy<br />

■ A table per concrete entity class<br />

■ A “join” strategy, where fields or properties that are specific to a subclass are mapped to a<br />

different table than the fields or properties that are common to the parent class<br />

<strong>The</strong> strategy is configured by setting the strategy element of @Inheritance to one of the<br />

options defined in the javax.persistence.InheritanceType enumerated type:<br />

public enum InheritanceType {<br />

SINGLE_TABLE,<br />

JOINED,<br />

TABLE_PER_CLASS<br />

};<br />

<strong>The</strong> default strategy is InheritanceType.SINGLE_TABLE, and is used if the @Inheritance<br />

annotation is not specified on the root class of the entity hierarchy.<br />

Entities<br />

Chapter 24 • Introduction to the <strong>Java</strong> Persistence API 691

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!