JBoss.org Community Documentation
The EJB specification allows you to map an entity bean to multiple tables. You do this by using the @SecondaryTable
annotation.
The org.jboss.tutorial.secondary.bean.Customer entity maps its address properties to a
separate ADDRESS table. The first thing it does is define the secondary table.
@Entity
@Table(name = "CUSTOMER")
@SecondaryTable(name = "EMBEDDED_ADDRESS", join = {@JoinColumn(name = "ADDRESS_ID")})
public class Customer implements java.io.Serializable
{
}
The @JoinColumn of the secondary table must match the value of the Customer's primary key. To map
individual properties to a secondary table you use the secondaryTable member value of @Column.
@Column(name = "STREET", secondaryTable = "EMBEDDED_ADDRESS")
public String getStreet()
{
return street;
}
To build and run the example, make sure you have installed JBoss 5.x. See the Section 1.1, “JBoss Application Server 5.x” for details.
From the command prompt, move to the "secondary" folder under the Section 1.3, “Set the EJB3_TUTORIAL_HOME”
Make sure your JBossAS-5.x is running
$ ant
$ ant run
run:
[java] Create Bill Burke and Monica Smith
[java] Bill and Monica get married
[java] Get all the Burkes
[java] There are now 2 Burkes
$ mvn clean install -PRunSingleTutorial
You can view the tables created by JBoss by going to the
Hypersonic Service,
scrolling down to the startDatabaseManager button and clicking it.
A Hypersonic SQL window will be minimized, but you can open it up to look at the tables and do queries.