This chapter illustrates integration of Guice with JPA 2 and Hibernate 3 in a web and stand-alone application. A familiarity with the JPA and Hibernate is desired, particularly in a web environment. However, we will begin with a gentle introduction to JPA and Hibernate. Post that, we will continue with our Struts 2 retrofitted application from the last chapter and make it driven by a JPA, Hibernate-backed database. In this process, we will see how to fit Guice in both standalone as well as a web application to be used as a persistence provider.
We will introduce the concept of transaction in a stand-alone application and in a web application with two strategies like Session per transaction and Session per request.