Skip to Main Content
Enterprise JavaBeans 3.1, 6th Edition
book

Enterprise JavaBeans 3.1, 6th Edition

by Andrew Lee Rubinger, Bill Burke
September 2010
Intermediate to advanced content levelIntermediate to advanced
766 pages
18h 35m
English
O'Reilly Media, Inc.
Content preview from Enterprise JavaBeans 3.1, 6th Edition

Table per Subclass

In the table per subclass mapping, each subclass has its own table, but this table contains only the properties that are defined on that particular class. In other words, it is similar to the TABLE_PER_CLASS strategy, except the schema is normalized. This is also called the JOINED strategy:

CREATE TABLE "PUBLIC"."JOINED_PERSON"
(
   ID bigint PRIMARY KEY NOT NULL,
   FIRSTNAME varchar,
   LASTNAME varchar
)
;

CREATE TABLE "PUBLIC"."JOINED_CUSTOMER"
(
   CITY varchar,
   STATE varchar,
   STREET varchar,
   ZIP varchar,
   ID bigint PRIMARY KEY NOT NULL
)
;
ALTER TABLE "PUBLIC"."JOINED_CUSTOMER"
ADD CONSTRAINT FK65AE08146E93989D
FOREIGN KEY (ID)
REFERENCES "PUBLIC"."JOINED_PERSON"(ID)
;

CREATE TABLE "PUBLIC"."JOINED_EMPLOYEE"
(
   EMPLOYEEID integer,
   EMP_PK bigint PRIMARY KEY NOT NULL
)
;
ALTER TABLE "PUBLIC"."JOINED_EMPLOYEE"
ADD CONSTRAINT FK88AF6EE4D423ED9D
FOREIGN KEY (EMP_PK)
REFERENCES "PUBLIC"."JOINED_CUSTOMER"(EMP_PK)
;

When the persistence manager loads an entity that is a subclass or traverses a polymorphic relationship, it does an SQL join on all the tables in the hierarchy. In this mapping, there must be a column in each table that can be used to join each table. In our example, the JOINED_EMPLOYEE, JOINED_CUSTOMER, and JOINED_PERSON tables share the same primary-key values. The annotation mapping is quite simple:

@Entity(name="JOINED_PERSON")
@Inheritance(strategy=InheritanceType.JOINED)
public class Person
{
   ...
}

@Entity(name="JOINED_CUSTOMER")
public class Customer extends Person ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Reinventing the Organization for GenAI and LLMs

Reinventing the Organization for GenAI and LLMs

Ethan Mollick
JavaServer Faces

JavaServer Faces

Hans Bergsten
EJB 3 Developer Guide

EJB 3 Developer Guide

Michael Sikora

Publisher Resources

ISBN: 9781449399139Errata Page