3.2.7. Mapping secondary tables
You can map a single entity bean to several tables using the
@SecondaryTable
or @SecondaryTables
class level annotations. To express that a column is in a particular table, use the table
parameter of @Column
or @JoinColumn
.
In this example,
name
will be in MainCat
. storyPart1
will be in Cat1
and storyPart2
will be in Cat2
. Cat1
will be joined to MainCat
using the cat_id
as a foreign key, and Cat2
using id
(ie the same column name, the MainCat
id column has). Plus a unique constraint on storyPart2
has been set.
Check out the JBoss EJB 3 tutorial or the Hibernate Annotations unit test suite for more examples.