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:

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

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

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

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.