Java Persistence APIs: Employee Registry Example (Enterprise JavaBeans 3.1)

 

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

tmp98-242

tmp98-243

tmp98-244

EmbeddedEmployeePK.java

tmp98-245

tmp98-246

tmp98-247

tmp98-248

EmployeeType.java

tmp98-249

EmployeeWithEmbeddedPK.java

tmp98-250

tmp98-251

EmployeeWithExternalCompositePK.java

tmp98-252tmp98-253

EmployeeWithMappedSuperClassId.java

tmp98-254

tmp98-255

tmp98-256

EmployeeWithProperties.java

tmp98-257

tmp98-258

tmp98-259

tmp98-260

ExternalEmployeePK.java

tmp98-261

 

tmp98-262

tmp98-263

tmp98-264

Address.java

tmp98-265

tmp98-266

tmp98-267

Computer.java

tmp98-268

tmp99-1_thumb[1]

tmp99-2_thumb[1]

Customer.java

tmp99-3_thumb[1]

tmp99-4_thumb[1]

tmp99-5_thumb[1]

Employee.java

tmp99-6_thumb

tmp99-7_thumb[1]

tmp99-8_thumb[1]

tmp99-9_thumb[1]

tmp99-10_thumb[1]

tmp99-11_thumb

Phone.java

tmp99-12_thumb[1]tmp99-13_thumb[1]

PhoneType.java

tmp99-14_thumbtmp99-15_thumb

Task.java

tmp99-16_thumb[1]

tmp99-17_thumb[1]

tmp99-18_thumb

Team.java

tmp99-19_thumb[1]

tmp99-20_thumb[2]

tmp99-21_thumb

Customer.java

tmp99-22_thumb[1]

tmp99-23_thumb[1]

tmp99-24_thumb

Employee.java

tmp99-25_thumb[1]tmp99-26_thumb

Person.java

tmp99-27_thumb[5]

tmp99-28_thumb[1]

tmp99-29_thumb[1]

Customer.java

 

tmp99-30_thumb

tmp99-31_thumb[1]

tmp99-32_thumb[1]

Employee.java

tmp99-33_thumb[1]

Person.java

tmp99-34_thumb[1]

tmp99-35_thumb[1]

tmp99-36_thumb[1]

tmp99-37_thumb[1]

Customer.java

 

tmp99-38_thumb[1]

tmp99-39_thumb[1]

tmp99-40_thumb[1]

Employee.java

tmp99-41_thumbtmp99-42_thumb

Person.java

tmp99-43_thumb

tmp99-44_thumb[1]

tmp99-45_thumb[1]

tmp99-46_thumb

EntityListenerEmployee.java

tmp99-47_thumb

tmp99-48_thumb[1]

tmp99-49_thumb[1]

tmp99-50_thumb

EventTracker.java

tmp99-51_thumbtmp99-52_thumb

persistence.xml

tmp99-53_thumb

Test Resources

EmployeeIntegrationTest.java

tmp99-54_thumb

tmp99-55_thumb[2]

tmp99-56_thumb[1]

tmp99-57_thumb[1]

tmp99-58_thumb[1]

tmp99-59_thumb[1]

tmp99-60_thumb[1]

tmp99-61_thumb[2]

tmp99-62_thumb[1]

tmp99-63_thumb[1]

tmp99-64_thumb[1]

tmp99-65_thumb[2]

tmp99-66_thumb[1]

tmp99-67_thumb[1]

tmp99-68_thumb[5]

tmp99-69_thumb[6]

 

 

tmp99-73_thumb[1]

tmp99-74_thumb[1]

 

tmp99-76_thumb[1]

tmp99-77_thumb[1]

tmp99-78_thumb[1]

tmp99-79_thumb[1]

tmp99-80_thumb[1]

tmp99-81_thumb[1]

tmp99-82_thumb[1]

tmp99-83_thumb

Next post:

Previous post: