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 Concrete Class

In the table per concrete class strategy, a database table is defined for each concrete class in the hierarchy. Each table has columns representing its properties and all properties of any superclasses:

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

CREATE TABLE "PUBLIC"."TABLEPERCLASS_CUSTOMER"
(
   ID bigint PRIMARY KEY NOT NULL,
   FIRSTNAME varchar,
   LASTNAME varchar,
   CITY varchar,
   STATE varchar,
   STREET varchar,
   ZIP varchar
)
;

CREATE TABLE "PUBLIC"."TABLEPERCLASS_EMPLOYEE"
(
   ID bigint PRIMARY KEY NOT NULL,
   FIRSTNAME varchar,
   LASTNAME varchar,
   CITY varchar,
   STATE varchar,
   STREET varchar,
   ZIP varchar,
   EMPLOYEEID integer
)
;

One major difference between this strategy and the SINGLE_TABLE strategy is that no discriminator column is needed in the database schema. Also notice that each table contains every persistent property in the hierarchy. Let’s now look at how we map this strategy with annotations:

@Entity(name = "TABLEPERCLASS_PERSON")
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
public class Person
{
   @Id
   @GeneratedValue(strategy = GenerationType.TABLE)
   // Cannot accept default generation strategy for table-per-class
   private Long id;

   private String firstName;
   private String lastName;
   ...
}

@Entity(name = "TABLEPERCLASS_CUSTOMER")
public class Customer extends Person
{
   private String street;
   private String city;
   private String state;
   private String zip;
   ...
}

@Entity(name = "TABLEPERCLASS_EMPLOYEE") ...
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