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 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
SimpleEmployee.java
EmbeddedEmployeePK.java
EmployeeType.java
EmployeeWithEmbeddedPK.java
EmployeeWithExternalCompositePK.java
EmployeeWithMappedSuperClassId.java
EmployeeWithProperties.java
ExternalEmployeePK.java
Address.java
Computer.java
Customer.java
Employee.java
Phone.java
PhoneType.java
Task.java
Team.java
Customer.java
Employee.java
Person.java
Customer.java
Employee.java
Person.java
Customer.java
Employee.java
Person.java
EntityListenerEmployee.java
EventTracker.java
persistence.xml
Test Resources
EmployeeIntegrationTest.java