I copied the original Chapter 6 into Chapter 6a, and removed the Main class from Chapter 6 and from the pom file so that I could deploy the EJB.
Chapter 6 code, with directory structure:
. JavaEE6
. pom.xml
. . Chapter06
. . pom.xml
… . src
… … main
… … . . java
… … … . com
… … … … apress
… … … … . . javaee6
… … … … … . chapter06
… … … … … … Book.java
… … … … … … BookEJB.java
… … … … … … BookEJBRemote.java
… … . . resources
… … … . META-INF
… … … … persistence.xml
… … test
… … . . java
… … … . com
… … … … apress
… … … … . . javaee6
… … … … … . chapter06
… … … … … … BookEJBTest.java
In Chapter 2, a Book entity was mapped to a Derby database table. A Main class used the entity manager to persist a book and retrieve all the books from the database using explicit transactional demarcation: tx.begin() and tx.commit().
The Chapter 6 example employs the same use case, but replaces the Main class used in Chapter 2 with a stateless session bean (BookEJB) which will handle Create, Read, Update, Delete (CRUD) operations on the Book entity. The BookEJB and the Book entity will then be packaged and deployed into GlassFish. The EJB needs a remote interface because an external client application (MainContainer class in chapter 6a) will invoke methods remotely on the EJB.





