Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Intro

The JPA module allows to define transactional beans or methods. It's similar to the annotation you might know from the Spring framework. It's a simple alternative to EJBs (e.g. if you don't have an EJB container).

Dependencies

The page CODI Modules provides an overview about CODI modules and how to add them to your project.

For using the features described in this page, you have to add:

  • CODI-Core
  • CODI-JPA module
  • JPA implementation of your choice
Tip
titleHint

For using @PersistenceContext you can use e.g. the resources-plugin of OpenWebBeans

Using one (default) Entity Manager

Code Block
java
java
titleProducer for a default entity manager
public class DataBaseProducer
{
    @Produces
    @PersistenceContext(unitName="default")
    @Default
    private EntityManager entityManager;

    public void dispose(@Disposes @Default EntityManager entityManager)
    {
        if(entityManager.isOpen())
        {
            entityManager.close();
        }
    }
}
Tip
titleHint

For using @PersistenceContext you can use e.g. the resources-plugin of OpenWebBeans

Code Block
java
java
titleUsing @Transactional
public class CustomService1
{
    @Inject
    protected EntityManager entityManager;

    @Transactional
    public void update(CustomEntity1 entity)
    {
        this.entityManager.merge(entity);
    }
}

...