Enterprise applications frequently need to deal with state which survives application restarts. We call this “persistent state,” and it’s typically modeled by a program called a relational database management system (RDBMS). Handling the transformation/mapping between the row-based RDBMS and Java objects is a rote process for application developers, so we offload this responsibility to the Java Persistence API (JPA). In this fashion we’re free to interact with regular getters/setters on Java objects while the mechanics of getting data into and out of the backing database is handled for us.
EJB integrates with JPA via the entity bean, and Chapters 9 through 14 detail the APIs needed to properly model, map, persist, and retrieve data with a real database. Our example is an employee registry, where we apply a variety of techniques to draw relationships between mapped types and query the DB efficiently.
Wiki article: http://community.jboss.org/docs/DOC-15572
Following is a full listing of all source code used in this runnable example.
See Chapter 9.
package org.jboss.ejb3.examples.employeeregistry.ch09.entitymanager; import javax.persistence.Entity; import javax.persistence.Id; /** * Represents an Employee in the system. ...