JBoss.org Community Documentation

Chapter 10. Introduction to embedding objects in EJB3 entities

The EJB3 specification allows you to embed plain Java objects within your entities and map the properties of this embedded value object to columns within the entity's table.

The org.jboss.tutorial.embeddable.bean.Customer entity encapsulates the name of the customer in the org.jboss.tutorial.embeddable.bean.Name value object. The org.jboss.tutorial.embeddable.bean.Name value object must be tagged with the @Embeddable annotation.

public class Name implements java.io.Serializable

The properties of Name must then be mapped to columns within Customer's table.

   @AttributeOverride(name = "first", column = {@Column(name = "FIRST_NAME")}),
   @AttributeOverride(name = "last", column = {@Column(name = "LAST_NAME")})
public Name getName()
   return name;

Building and Running

From the command prompt, move to the "embeddable" folder under the Section 1.3, “Set the EJB3_TUTORIAL_HOME”

Ant Users:

Make sure your JBossAS-5.x is running

$ ant
$ ant 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
Maven Users: Make sure the AS is not running.
$ mvn clean install -PRunSingleTutorial
View the tables and rows:

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.