Java Reference
In-Depth Information
Figure 9.9. Bidder and Seller inherit shared properties from User .
This is so common in OO design that most Java developers don't give it a second thought.
It's obvious that Bidder and Seller should inherit from User . But for DBAs, this ob-
ject inheritance is of great concern. Why? Because most databases don't support inher-
itance between tables (PostgreSQL has table inheritance, but this isn't common). So the
question DBAs have to face is how to map an inheritance object hierarchy like that of fig-
ure 9.9 to relational database tables. There are three strategies for doing this:
• Single-table
• Joined-tables
• Table-per-class
9.5.1. Single-table strategy
In the single-table strategy, which is the default inheritance strategy for JPA, all classes in
the domain model hierarchy are mapped to one table. This means a single table will store
all data from all the objects in the domain model. Different objects in the domain model are
identified using a special column called a discriminator column. In effect, the discriminat-
or column contains a value unique to the object type in a given row (see section 9.3.5 on
enumerated types). The best way to understand this scheme is to see it implemented. For
the ActionBazaar schema, assume that all user types, including Bidders and Seller s,
are mapped into the USERS table. Figure 9.10 shows how the table might look.
 
Search WWH ::




Custom Search