Overview
Other MyFaces Extensions
- ExtVal
- Ext-Script
- [Orchestra]
- [Portlet Bridge]
Community
Development
Sponsorship
Your browser does not support iframes
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).
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 the core and the JPA module.
Hint
For using @PersistenceContext
you can use e.g. the resources-plugin of OpenWebBeans
public class DataBaseProducer { @Produces @PersistenceContext(unitName="default") @Default private EntityManager entityManager; public void dispose(@Disposes @Default EntityManager entityManager) { if(entityManager.isOpen()) { entityManager.close(); } } }
public class CustomService1 { @Inject protected EntityManager entityManager; @Transactional public void update(CustomEntity1 entity) { this.entityManager.merge(entity); } }
public class DataBaseProducer { @Produces @PersistenceContext(unitName="default") @Default private EntityManager entityManager; @Produces @PersistenceContext(unitName="UserDB") @Users private EntityManager usersEntityManager; public void disposeDefaultDB(@Disposes @Default EntityManager entityManager) { if(entityManager.isOpen()) { entityManager.close(); } } public void disposeUserDB(@Disposes @Users EntityManager entityManager) { if(entityManager.isOpen()) { entityManager.close(); } } }
public class CustomService2 { @Inject @Users protected EntityManager entityManager; @Transactional(Users.class) public void update(CustomEntity2 entity) { this.entityManager.merge(entity); } }