Chapter WORKBOOK 3. Exercises for Chapter 5

Chapter 5 of the EJB book walked you through all of the details for deploying, creating, and interacting with the EntityManager interface. This chapter uses the same Cabin entity bean introduced in Chapter 4 to illustrate the concepts and APIs discussed in Chapter 5. You will see examples of:

  • The merge( ), flush( ), and refresh( ) operations in action

  • An explanation of FlushModeType

  • The differences between a transaction-only and an extended persistence context

  • Using Java Persistence in a standalone Java application

Exercise 5.1 walks you through the first three bullets, and Exercise 5.2 shows you how to use persistence outside of the application server.

Exercise 5.1: Interacting with EntityManager

This exercise has four different clients to build and run against the JBoss application server:

Client_1.java

This client demonstrates what happens when you use the EntityManager.merge( ) operation. It interacts with the TravelAgent EJB.

Client_2.java

This client demonstrates the difference between a transaction-only and an extended persistence context. The TransactionPersistenceContext EJB injects and uses a transaction-scoped entity manager. The ExtendedPersistenceContext EJB injects and uses an extended entity manager.

Client_3.java

This client demonstrates how FlushModeType affects your application—specifically, when updates are synchronized with the database.

These clients must be executed in order; Client_1 creates a Cabin entity that is used by ...

Get Enterprise JavaBeans 3.0, 5th Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.