Skip to content
sclassen edited this page Jan 4, 2013 · 2 revisions

guice-jpa – a guice-persist alternative

The official guice extension guice-persist allows to configure and inject a persistence unit into your classes.
Guice-persist asumes that only one peristence unit is used in an application and that this peristence unit is application managed.

Guice-jta overcomes this shortcoming. It supports

  • multiple peristence units
  • application manged and container managed persistence units
  • resourec local and JTA transactions.
    Currently not supported is:
  • @Finder annotation
  • Mixing annotated and non annotated peristence units.

Guice-jta is inspired and based upon guice-persist. Most of the concepts and ideas have been adapted and/or reused.

  • UnitOfWork as the lifecycle manager for EntityManagers.
  • PersistFilter for spanning a UnitOfWork around a request.
  • PersistenceService for starting and stoppin the entire persistence engine.
  • @Transactional annotation on methods to spann a transaction around the method.

The most notable changes to guice-persist:

  • EntityManager cannot be injected. Instead an EntityManagerProvider has to be injected. See the documentation of EntityManagerProvider for details.
  • @Transactional annotation allows to specify which peristence units are involved in the transaction.
  • UnitOfWork has a new method isActive()
  • Retrieving an EntityManager does not start a UnitOfWork. Instead it will throw an Exception if the UnitOfWork is not active.
  • PersistenceService can be restarted after it has been stopped.
  • @Finder annotation is not yet supported
Clone this wiki locally