Appendix F. Java Persistence APIs: Employee Registry Example

Description

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.

Source Listing

Following is a full listing of all source code used in this runnable example.

Implementation Resources

See Chapter 9.

SimpleEmployee.java

package org.jboss.ejb3.examples.employeeregistry.ch09.entitymanager; import javax.persistence.Entity; import javax.persistence.Id; /** * Represents an Employee in the system. ...

Get Enterprise JavaBeans 3.1, 6th Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.