Java Reference
In-Depth Information
Mapping an entity to multiple tables
The @SecondaryTables (plural) and @SecondaryTable (singular) annotations al-
low JPA to handle the cases where an entity's data must come from two or more tables.
In some rare situations, this is a very sensible strategy. Let's consider the User entity in
listing 9.2 . The User entity contains a byte array picture property. The DBA for Ac-
tionBazaar decided to store the data across the USERS and USER_PICTURES tables, as
shown in figure 9.5 .
Figure 9.5. Storing user data across two tables
This makes excellent sense because the USER_PICTURES table stores large binary images
that could significantly slow down queries using the table. The @Secondary-Table an-
notation enables you to get entity data from more than one table and is defined as follows:
 
Search WWH ::




Custom Search