O'Reilly logo

Enterprise JavaBeans 3.0, 5th Edition by Bill Burke, Richard Monson-Haefel

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required