The extension guice-persist provides various classes, which facilitate the injection of EntityManger
in our data access layer classes.
PersistService
is an interface, exposing two APIs, start and stop. The implementations of these two APIs means preparing and destroying the EntityManagerFactory
instance, using Persistence.createEntityManagerFactory()
API.
UnitOfWork is an interface, exposing two APIs, begin()
and end()
. The implementations of these two APIs necessarily mean creating an EntityManager
instance using the EntityManagerFactory
created earlier. It serves an essential purpose, because it opens the session for read-only operations, and closes them accordingly.