You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@aries.apache.org by Mansour Al Akeel <ma...@gmail.com> on 2014/03/09 23:02:14 UTC
Wrap persistence calls in a container managed transaction
I have an osgi bundle that load initialization data from other
bundles. When ever another component is started, the data loader
checks to see if a specific file exists and if that bundle has JPA
capabilites. This is done by obtaining EntityManagerFactory for the
loaded bundle.
For example, if bundle A is started, the data loader, gets the
EntityManagerFactory from bundle A, and loads the data from the file.
This has been working fine with App managed persistence:
BundleContext sourceContext = bundle.getBundleContext();
ServiceReference<?> emfSr =
sourceContext.getServiceReference(EntityManagerFactory.class.getName());
ServiceReference<?> emSr =
sourceContext.getServiceReference(EntityManager.class.getName());
// start transaction when RESOUCE_LOCAL
// perform insert/update
//comit
The problem is when we have transaction-type="JTA". In this case the
entity manager has to be injected and the container needs to handle
the TX.
I like to get this to work in both cases
(transaction-type="RESOURCE_LOCAL" or "JTA").
Is there a way to gain control of container managed transactions ??
Thank you.