karaf-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Timothy Ward <tim.w...@paremus.com>
Subject Re: Antw: Re: OSGi Transaction control fails with hibernate
Date Wed, 13 Sep 2017 11:18:34 GMT
Hi Alexander,

So what you’re doing is passing a fully configured EntityManagerFactory to the resource
provider factory. If you create the provider this way then you are responsible for setting
up all of the EntityManagerFactory’s configuration, including how it’s going to integrate
with transaction control. For local transactions there is nothing to integrate with , but
in the general case this is actually quite hard to do, and I would advise not trying to do
it.

As you can see the EntityManagerFactory version of the provider factory <https://github.com/apache/aries/blob/ed8dbc79758766081203056cff27eb0bcbd7efb3/tx-control/tx-control-providers/jpa/tx-control-provider-jpa-xa/src/main/java/org/apache/aries/tx/control/jpa/xa/impl/JPAEntityManagerProviderFactoryImpl.java#L122>
does quite a bit less setup on your behalf than the configuration-driven version does <https://github.com/apache/aries/blob/ed8dbc79758766081203056cff27eb0bcbd7efb3/tx-control/tx-control-providers/jpa/tx-control-provider-jpa-xa/src/main/java/org/apache/aries/tx/control/jpa/xa/impl/XAJPAEMFLocator.java#L72>.
If you were to 
provide a factory configuration for the “org.apache.aries.tx.control.jpa.xa” pid containing
“osgi.unit.name=<your persistence unit’s name>” and any necessary datasource configuration
(i.e. that’s not coming from the persistence xml) then you could inject the JPAEntityManagerProvider
directly as a service.

More documentation about configuration-driven resources for Aries Tx-Control is available
at http://aries.apache.org/modules/tx-control/xaJPA.html#creating-a-resource-using-a-factory-configuration
<http://aries.apache.org/modules/tx-control/xaJPA.html#creating-a-resource-using-a-factory-configuration>

Another thing that probably could be done would be to look at dynamically installing the plugin
when using the EntityManagerFactoryBuilder version of the factory method. This, however, would
need a patch to Aries Transaction Control, and would still not make your existing code work.

Regards,

Tim


> On 13 Sep 2017, at 10:59, <alexander.sahler@brodos.de> <alexander.sahler@brodos.de>
wrote:
> 
> Hi Tim,
> 
> I use a JPAEntityManagerProviderFactory (providerFactory) which I inject as a service
reference into my repository class.
> Furthermore, I inject a EntityManagerFactory (emf) into the repository class as well
as the TransactionControl (txControl).
> 
> The provider Factory is created by pax-jdbc (I use hibernate).
> 
> This provider factory is then used to get the Entity manager like this:
> 
> EntityManager em = providerFactory.getProviderFor(emf, null).getResource(txControl);
> 
> It fails giving an exception telling that transaction cannot be joined, because it's
not open.
> 
> The wrapping call is like this:
> txControl.build()
>                 .required(
>                         () -> repo.store(article));
> 
> Best, Alexander.
> 
> 
> 
> Hi Alexander,
> 
> Do you have a code example of how you’re obtaining and using the EntityManager? There
should be no usage of the OSGiJtaPlatform from the tx-control XA JPA resource provider, which
means that there’s either a bug in the resource provider, or something is misconfigured.
If you are a member of the Aries user mailing list then that would be a better place to continue
this discussion.
> 
> Regards,
> 
> Tim
> 
>> On 13 Sep 2017, at 09:21, Guillaume Nodet <gnodet@apache.org <mailto:gnodet@apache.org>>
wrote:
>> 
>> Fwiw, you should ask on the Aries mailing list, where tx-control is developed.
>> 
>> I've recently worked on a new project called pax-transx which provides an abstraction
layer on top of transaction managers so that some features can be accessed in a common way.
 I think this should be used in tx-control instead of wrapping the tm again and not being
flexible.
>> Right now, tx-control uses its own instance of transaction manager and there's no
way around afaik, so you can't use the karaf transaction feature if you want to use it.
>> Anyway, I'd gladly support you if you go to the aries mailing list to raise this
point !
>> 
>> 2017-09-13 9:52 GMT+02:00 <alexander.sahler@brodos.de <mailto:alexander.sahler@brodos.de>>:
>> Hello.
>> 
>> I'm trying to get tx-control with XA transactions running (local is working).
>> I found that tx-control opens a JTA transaction using RecoveryWorkAroundTransactionManager
(derived from geronimo's TransactionManager Implementation) explicitly instead of using the
registered TransactionManager (aries in my case for karaf 4.0.9). When hibernate EntityManager
implementation tries to join the transaction it fails because it uses the TransactionManager
provided by OsgiJtaPlatform (from hibernate-osgi) which is of course the one registered in
osgi ecosystem.
>> 
>> I think that the tx-control implementation has to use the TransactionManager registered
with OSGi.
>> 
>> Has anyone got that thing ever running?
>> 
>> Best Alexander.
>> 
>> 
>> 
>> -- 
>> ------------------------
>> Guillaume Nodet
>> 
> 


Mime
View raw message