Versions Compared

Key

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

...

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

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

...

Code Block
java
java
titleUsing @Transactional and an entity manager with a qualifier
//...
public class CustomService2
{
    @Inject
    @Users
    protected EntityManager entityManager;

    @Transactional(Users.class)
    public void update(CustomEntity2 entity)
    {
        this.entityManager.merge(entity);
    }
}

EntityManager injection without producer (CODI v1.0.3+)

Code Block
java
java
titleUsing @Transactional and @PersistenceContext without producer

//...
public class CustomService3
{
    @PersistenceContext(unitName = "default")
    private EntityManager entityManager;

    @Transactional
    public void delete(Entity entity)
    {
        this.entityManager.remove(em.merge(entity));
    }

    @PreDestroy
    public void cleanup()
    {
        if(this.entityManager.isOpen())
        {
            this.entityManager.close();
        }
    }
} 



...

Extended Persistence Contexts

...