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 5. Exercises for Chapter 7

Chapter 7 of the EJB book walked you through the seven relationship types. The exercises in this chapter implement all of the entities mentioned in Chapter 7. You will get to see how these entities and their relationships are created and how Hibernate autogenerates the database schema. You will also see how cascading and lazy loading affect your applications.

Exercise 7.1: Cascading

This exercise shows you how cascading affects the operation of entity manager life cycle methods. The examples in this section do not require the JBoss application server to run, and they use the Hibernate standalone persistence implementation of Java Persistence. Two client applications demonstrate the concepts of cascading:

Client1.java

This client shows how cascading affects the operation of the persist( ), merge( ), and remove( ) methods of the EntityManager interface.

Client2.java

This client shows you how the merge( ) operation can also persist new related entities.

Start Up JBoss

There is no need to start up JBoss in this example because standalone persistence is being used.

Initialize the Database

The database tables will be created when the clients in this exercise run. The database is an in-memory-only database and will not be available when the program completes.

Build the Example Programs

Perform the following steps:

  1. Open a command prompt or shell terminal and change to the ex07_1 directory created by the extraction process.

  2. Set the JAVA_HOME and JBOSS_HOME ...

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