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( )
, andremove( )
methods of theEntityManager
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:
Open a command prompt or shell terminal and change to the ex07_1 directory created by the extraction process.
Set the
JAVA_HOME
andJBOSS_HOME ...
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.