Package com.isomorphic.jpa
Class EMFProviderCMT
java.lang.Object
com.isomorphic.jpa.EMFProviderCMT
- All Implemented Interfaces:
EMFProviderInterface
EMF provider for Container Managed Transactions (CMT).
Use this provider if you want to use JPA data source in EJB environment (accessing JPA data source from enterprise bean). Values from jpa.entityManager and jpa.entityManagerFactory properties are used to locate EntityManager and EntityManagerFactory in container's environment context via JNDI. For this implementation to work persistence-context-ref and persistence-unit-ref should be declared for enterprise bean in /META-INF/ejb-jar.xml. For example:
<?xml version="1.0" encoding="UTF-8"?>
<ejb-jar
version = "3.0"
xmlns = "http://java.sun.com/xml/ns/javaee"
xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation = "http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/ejb-jar_3_0.xsd">
<enterprise-beans>
<session>
<ejb-name>TestEJB</ejb-name>
<persistence-context-ref>
<persistence-context-ref-name>REFERENCE_TO_ENTITY_MANAGER</persistence-context-ref-name>
<persistence-unit-name>PERSISTENCE_UNIT_NAME</persistence-unit-name>
</persistence-context-ref>
<persistence-unit-ref>
<persistence-unit-ref-name>REFERENCE_TO_ENTITY_MANAGER_FACTORY</persistence-unit-ref-name>
<persistence-unit-name>PERSISTENCE_UNIT_NAME</persistence-unit-name>
</persistence-unit-ref>
</session>
</enterprise-beans>
</ejb-jar>
getTransaction() will return instance of EJBContext located in "java:comp/EJBContext" in JNDI. Transaction will be committed by container. To roll back transaction EJBContext.setRollbackOnly() is used.-
Field Summary
FieldsModifier and TypeFieldDescriptionName of the reference to managed entity manager factory.Name of the reference to container managed entity manager.Fields inherited from interface com.isomorphic.jpa.EMFProviderInterface
ENTITY_MANAGER, ENTITY_MANAGER_FACTORY, JPA_ENTITY_MANAGER, JPA_ENTITY_MANAGER_FACTORY, JPA_PERSISTENCE_UNIT_NAME, JPA_TRANSACTION, PERSISTENCE_UNIT_NAME, TRANSACTION -
Constructor Summary
ConstructorsConstructorDescriptionCreates new EMF provider.EMFProviderCMT(String entityManagerRef, String entityManagerFactoryRef) Creates new EMF provider with specified context reference names.EMFProviderCMT(Properties config) Creates new EMF provider. -
Method Summary
Modifier and TypeMethodDescriptionvoidDoes nothing - container will commit transaction.jakarta.persistence.EntityManagerFactoryget()ReturnsEntityManagerFactoryfound in container's environment context.jakarta.persistence.EntityManagerReturnsEntityManagerfound in container's environment context.getTransaction(jakarta.persistence.EntityManager em) ReturnsEJBContextfound in container's environment context.voidreturnEntityManager(jakarta.persistence.EntityManager em) Does nothing - container will closeEntityManager.voidSets rollback flag for transaction bytx.setRollbackOnly().
-
Field Details
-
entityManagerRef
Name of the reference to container managed entity manager. -
entityManagerFactoryRef
Name of the reference to managed entity manager factory.
-
-
Constructor Details
-
EMFProviderCMT
public EMFProviderCMT()Creates new EMF provider. Values from jpa.entityManager and jpa.entityManagerFactory properties are used to locateEntityManagerandEntityManagerFactoryin container's environment context. -
EMFProviderCMT
Creates new EMF provider. Values from provided properties entityManager and entityManagerFactory are used to locateEntityManagerandEntityManagerFactoryin container's environment context.- Parameters:
config-Propertiesfor provider configuration.
-
EMFProviderCMT
Creates new EMF provider with specified context reference names.- Parameters:
entityManagerRef-Stringname of context reference to entity manager.entityManagerFactoryRef-Stringname of context reference to entity manager factory.
-
-
Method Details
-
get
public jakarta.persistence.EntityManagerFactory get()ReturnsEntityManagerFactoryfound in container's environment context.- Specified by:
getin interfaceEMFProviderInterface- Returns:
EntityManagerFactorycan be used to acquire meta-data (for JPA 2.0) or implement "application managed entity manager" pattern.
-
getEntityManager
public jakarta.persistence.EntityManager getEntityManager() throws jakarta.persistence.PersistenceExceptionReturnsEntityManagerfound in container's environment context.- Specified by:
getEntityManagerin interfaceEMFProviderInterface- Returns:
EntityManagerfor persistence operations.- Throws:
jakarta.persistence.PersistenceException- if unable to acquireEntityManager.
-
returnEntityManager
public void returnEntityManager(jakarta.persistence.EntityManager em) Does nothing - container will closeEntityManager.- Specified by:
returnEntityManagerin interfaceEMFProviderInterface- Parameters:
em-EntityManagerwhich should be closed.
-
getTransaction
ReturnsEJBContextfound in container's environment context.- Specified by:
getTransactionin interfaceEMFProviderInterface- Parameters:
em-EntityManagerneeded if joining to existing transaction or null.- Returns:
ObjectTransaction for persistence operations.- Throws:
jakarta.persistence.PersistenceException- if unable to acquire or open transaction.Exception- if unable to acquire or open transaction.
-
commitTransaction
Does nothing - container will commit transaction.- Specified by:
commitTransactionin interfaceEMFProviderInterface- Parameters:
tx-Objecttransaction to be commited.- Throws:
Exception- occured while committing transaction.
-
rollbackTransaction
Sets rollback flag for transaction bytx.setRollbackOnly().- Specified by:
rollbackTransactionin interfaceEMFProviderInterface- Parameters:
tx-Objecttransaction to be rolled back.
-