Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 87B38200CF3 for ; Wed, 13 Sep 2017 16:43:08 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 865E41609CA; Wed, 13 Sep 2017 14:43:08 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id D69181609C9 for ; Wed, 13 Sep 2017 16:43:06 +0200 (CEST) Received: (qmail 80687 invoked by uid 500); 13 Sep 2017 14:43:05 -0000 Mailing-List: contact user-help@karaf.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: user@karaf.apache.org Delivered-To: mailing list user@karaf.apache.org Received: (qmail 80677 invoked by uid 99); 13 Sep 2017 14:43:05 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd3-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 13 Sep 2017 14:43:05 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd3-us-west.apache.org (ASF Mail Server at spamd3-us-west.apache.org) with ESMTP id 23EE0185B9F for ; Wed, 13 Sep 2017 14:43:05 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd3-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 2 X-Spam-Level: ** X-Spam-Status: No, score=2 tagged_above=-999 required=6.31 tests=[HTML_MESSAGE=2, RCVD_IN_DNSWL_NONE=-0.0001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001] autolearn=disabled Received: from mx1-lw-eu.apache.org ([10.40.0.8]) by localhost (spamd3-us-west.apache.org [10.40.0.10]) (amavisd-new, port 10024) with ESMTP id uIsjtufY13Wl for ; Wed, 13 Sep 2017 14:42:58 +0000 (UTC) Received: from mail.brodos.de (mail.contentcard.com [194.153.150.18]) by mx1-lw-eu.apache.org (ASF Mail Server at mx1-lw-eu.apache.org) with ESMTPS id 2634B5F523 for ; Wed, 13 Sep 2017 14:42:58 +0000 (UTC) X-Assp-Version: 2.5.3(16347) on ASSP.dingdong X-Assp-ID: ASSP.dingdong id-13773-07581 X-Assp-Session: 7FB5731EFC78 (mail 1) X-Assp-Envelope-From: alexander.sahler@brodos.de X-Assp-Intended-For: user@karaf.apache.org X-Assp-Original-Subject: Re: Antw: Re: OSGi Transaction control fails with hibernate Message-Id: <59B943E5020000560015507B@GWCL-GWIA-SERVER.brodosmit.de> X-Mailer: Novell GroupWise Internet Agent 14.2.2 Date: Wed, 13 Sep 2017 16:42:45 +0200 From: To: "user@karaf.apache.org" Subject: Re: Antw: Re: OSGi Transaction control fails with hibernate References: <59B8E3A80200005600154FB8@GWCL-GWIA-SERVER.brodosmit.de> <59B8E3A80200005600154FB8@GWCL-GWIA-SERVER.brodosmit.de> <59B9019C020000560015501E@GWCL-GWIA-SERVER.brodosmit.de> <08196F4B-5B70-4D31-8764-A8696EA0BC64@paremus.com> In-Reply-To: <08196F4B-5B70-4D31-8764-A8696EA0BC64@paremus.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=__Part3E06D3F5.0__=" archived-at: Wed, 13 Sep 2017 14:43:08 -0000 This is a MIME message. If you are reading this text, you may want to consider changing to a mail reader or gateway that understands how to properly handle MIME multipart messages. --=__Part3E06D3F5.0__= Content-Type: multipart/alternative; boundary="=__Part3E06D3F5.1__=" --=__Part3E06D3F5.1__= Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Thanks Tim for the update. I tried the approach with providing a factory config in karaf.dir/etc/org.apache.aries.tx.control.jpa.xa.cfg with config as: osgi.unit.name=3DDSContext2 osgi.jdbc.driver.class=3Dorg.h2.Driver url=3Djdbc:h2:mem:article user=3Dsa password=3D whilst having a mininmal persistence.xml like: (without the dialect I see another exception; Access to DialectResolutionInfo cannot be null when 'hibernate.dialect' not set). Now I get further in the process (transaction enlistment works) but when actually accessing the database, the entity manager throws a NPE while trying to open the connection. In JPAEntityManagerProviderFactoryImpl.EnlistingDataSource.enlistedConnection(= ) while calling supplier.call, the supplier.delegate member is null: org.osgi.service.transaction.control.TransactionException: There was a problem getting hold of a database connection at org.apache.aries.tx.control.jpa.xa.impl.JPAEntityManagerProviderFactoryImpl= $EnlistingDataSource.enlistedConnection(JPAEntityManagerProviderFactoryImpl= .java:241) ~[?:?] at org.apache.aries.tx.control.jpa.xa.impl.JPAEntityManagerProviderFactoryImpl= $EnlistingDataSource.getConnection(JPAEntityManagerProviderFactoryImpl.java= :193) ~[?:?] at org.hibernate.engine.jdbc.connections.internal.DatasourceConnectionProvider= Impl.getConnection(DatasourceConnectionProviderImpl.java:122) ~[?:?] at org.hibernate.internal.NonContextualJdbcConnectionAccess.obtainConnection(N= onContextualJdbcConnectionAccess.java:35) ~[?:?] at org.hibernate.resource.jdbc.internal.LogicalConnectionManagedImpl.acquireCo= nnectionIfNeeded(LogicalConnectionManagedImpl.java:99) ~[?:?] at org.hibernate.resource.jdbc.internal.LogicalConnectionManagedImpl.getPhysic= alConnection(LogicalConnectionManagedImpl.java:129) ~[?:?] at org.hibernate.engine.jdbc.internal.StatementPreparerImpl.connection(Stateme= ntPreparerImpl.java:47) ~[?:?] at org.hibernate.engine.jdbc.internal.StatementPreparerImpl$5.doPrepare(Statem= entPreparerImpl.java:146) ~[?:?] at org.hibernate.engine.jdbc.internal.StatementPreparerImpl$StatementPreparati= onTemplate.prepareStatement(StatementPreparerImpl.java:172) ~[?:?] at org.hibernate.engine.jdbc.internal.StatementPreparerImpl.prepareQueryStatem= ent(StatementPreparerImpl.java:148) ~[?:?] at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1940) ~[?:?] at org.hibernate.loader.Loader.executeQueryStatement(Loader.java:1909) ~[?:?] at org.hibernate.loader.Loader.executeQueryStatement(Loader.java:1887) ~[?:?] at org.hibernate.loader.Loader.doQuery(Loader.java:932) ~[?:?] at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.j= ava:349) ~[?:?] at org.hibernate.loader.Loader.doList(Loader.java:2615) ~[?:?] at org.hibernate.loader.Loader.doList(Loader.java:2598) ~[?:?] at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2430) ~[?:?] at org.hibernate.loader.Loader.list(Loader.java:2425) ~[?:?] at org.hibernate.loader.custom.CustomLoader.list(CustomLoader.java:335) ~[?:?] at org.hibernate.internal.SessionImpl.listCustomQuery(SessionImpl.java:2153) ~[?:?] at org.hibernate.internal.AbstractSharedSessionContract.list(AbstractSharedSes= sionContract.java:991) ~[?:?] at org.hibernate.query.internal.NativeQueryImpl.doList(NativeQueryImpl.java:14= 7) ~[?:?] at org.hibernate.query.internal.AbstractProducedQuery.list(AbstractProducedQue= ry.java:1410) ~[?:?] at org.hibernate.query.internal.AbstractProducedQuery.getSingleResult(Abstract= ProducedQuery.java:1459) ~[?:?] at com.brodos.ds.persistence.h2.TestRepositoryImpl.lambda$checkHealth$0(TestRe= positoryImpl.java:47) ~[?:?] at org.apache.aries.tx.control.service.common.impl.AbstractT ransactionControlImpl$TransactionBuilderImpl.doWork(AbstractTransactionCont= rolImpl.java:161) [241:tx-control-service-xa:0.0.3] at org.apache.aries.tx.control.service.common.impl.AbstractTransactionControlI= mpl$TransactionBuilderImpl.required(AbstractTransactionControlImpl.java:84)= [241:tx-control-service-xa:0.0.3] at org.apache.aries.tx.control.service.common.impl.AbstractTransactionControlI= mpl.required(AbstractTransactionControlImpl.java:263) [241:tx-control-service-xa:0.0.3] at com.brodos.ds.persistence.h2.TestRepositoryImpl.checkHealth(TestRepositoryI= mpl.java:44) [160:com.brodos.example.ds.DSContext-infrastructure:1.0.0.SNAPSHOT] at com.brodos.ds.service.impl.MainHealthCheck.checkHealth(MainHealthCheck.java= :29) [209:com.brodos.example.ds.DSContext-service:1.0.0.SNAPSHOT] at com.brodos.ds.application.boundary.impl.HealthCheckImpl.checkHealth(HealthC= heckImpl.java:37) [212:com.brodos.example.ds.DSContext-application:1.0.0.SNAPSHOT] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:?] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:6= 2) ~[?:?] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImp= l.java:43) ~[?:?] at java.lang.reflect.Method.invoke(Method.java:497) ~[?:?] at org.apache.cxf.service.invoker.AbstractInvoker.performInvocation(AbstractIn= voker.java:180) [84:org.apache.cxf.cxf-core:3.1.12] at org.apache.cxf.service.invoker.AbstractInvoker.invoke(AbstractInvoker.java:= 96) [84:org.apache.cxf.cxf-core:3.1.12] at org.apache.cxf.jaxrs.JAXRSInvoker.invoke(JAXRSInvoker.java:189) [85:org.apache.cxf.cxf-rt-frontend-jaxrs:3.1.12] at org.apache.cxf.jaxrs.JAXRSInvoker.invoke(JAXRSInvoker.java:99) [85:org.apache.cxf.cxf-rt-frontend-jaxrs:3.1.12] at org.apache.cxf.interceptor.ServiceInvokerInterceptor$1.run(ServiceInvokerIn= terceptor.java:59) [84:org.apache.cxf.cxf-core:3.1.12] at org.apache.cxf.interceptor.ServiceInvokerInterceptor.handleMessage(ServiceI= nvokerInterceptor.java:96) [84:org.apache.cxf.cxf-core:3.1.12] at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChai= n.java:308) [84:org.apache.cxf.cxf-core:3.1.12] at org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationO= bserver.java:121) [84:org.apache.cxf.cxf-core:3.1.12] at org.apache.cxf.transport.http.AbstractHTTPDestination.invoke(AbstractHTTPDe= stination.java:263) [92:org.apache.cxf.cxf-rt-transports-http:3.1.12] at org.apache.cxf.transport.servlet.ServletController.invokeDestination(Servle= tController.java:234) [92:org.apache.cxf.cxf-rt-transports-http:3.1.12] at org.apache.cxf.transport.servlet.ServletController.invoke(ServletController= .java:208) [92:org.apache.cxf.cxf-rt-transports-http:3.1.12] at org.apache.cxf.transport.servlet.ServletController.invoke(ServletController= .java:160) [92:org.apache.cxf.cxf-rt-transports-http:3.1.12] at org.apache.cxf.transport.servlet.CXFNonSpringServlet.invoke(CXFNonSpringSer= vlet.java:189) [92:org.apache.cxf.cxf-rt-transports-http:3.1.12] at org.apache.cxf.transport.servlet.AbstractHTTPServlet.handleRequest(Abstract= HTTPServlet.java:299) [92:org.apache.cxf.cxf-rt-transports-http:3.1.12] at org.apache.cxf.transport.servlet.AbstractHTTPServlet.doGet(AbstractHTTPServ= let.java:223) [92:org.apache.cxf.cxf-rt-transports-http:3.1.12] at javax.servlet.http.HttpServlet.service(HttpServlet.java:687) [69:javax.servlet-api:3.1.0] at org.apache.cxf.transport.servlet.AbstractHTTPServlet.service(AbstractHTTPSe= rvlet.java:274) [92:org.apache.cxf.cxf-rt-transports-http:3.1.12] at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:845) [128:org.eclipse.jetty.servlet:9.3.14.v20161028] at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:584) [128:org.eclipse.jetty.servlet:9.3.14.v20161028] at org.ops4j.pax.web.service.jetty.internal.HttpServiceServletHandler.doHandle= (HttpServiceServletHan dler.java:71) [150:org.ops4j.pax.web.pax-web-jetty:6.0.6] at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:14= 3) [127:org.eclipse.jetty.server:9.3.14.v20161028] at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:548)= [125:org.eclipse.jetty.security:9.3.14.v20161028] at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.jav= a:226) [127:org.eclipse.jetty.server:9.3.14.v20161028] at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.jav= a:1180) [127:org.eclipse.jetty.server:9.3.14.v20161028] at org.ops4j.pax.web.service.jetty.internal.HttpServiceContext.doHandle(HttpSe= rviceContext.java:284) [150:org.ops4j.pax.web.pax-web-jetty:6.0.6] at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:512) [128:org.eclipse.jetty.servlet:9.3.14.v20161028] at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java= :185) [127:org.eclipse.jetty.server:9.3.14.v20161028] at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java= :1112) [127:org.eclipse.jetty.server:9.3.14.v20161028] at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:14= 1) [127:org.eclipse.jetty.server:9.3.14.v20161028] at org.ops4j.pax.web.service.jetty.internal.JettyServerHandlerCollection.handl= e(JettyServerHandlerCollection.java:80) [150:org.ops4j.pax.web.pax-web-jetty:6.0.6] at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:= 134) [127:org.eclipse.jetty.server:9.3.14.v20161028] at org.eclipse.jetty.server.Server.handle(Server.java:534) [127:org.eclipse.jetty.server:9.3.14.v20161028] at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:320) [127:org.eclipse.jetty.server:9.3.14.v20161028] at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:251)= [127:org.eclipse.jetty.server:9.3.14.v20161028] at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConn= ection.java:273) [119:org.eclipse.jetty.io:9.3.14.v20161028] at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:95) [119:org.eclipse.jetty.io:9.3.14.v20161028] at org.eclipse.jetty.io.SelectChannelEndPoint$2.run(SelectChannelEndPoint.java= :93) [119:org.eclipse.jetty.io:9.3.14.v20161028] at org.eclipse.jetty.util.thread.strategy.ExecuteProduceConsume.executeProduce= Consume(ExecuteProduceConsume.java:303) [130:org.eclipse.jetty.util:9.3.14.v20161028] at org.eclipse.jetty.util.thread.strategy.ExecuteProduceConsume.produceConsume= (ExecuteProduceConsume.java:148) [130:org.eclipse.jetty.util:9.3.14.v20161028] at org.eclipse.jetty.util.thread.strategy.ExecuteProduceConsume.run(ExecutePro= duceConsume.java:136) [130:org.eclipse.jetty.util:9.3.14.v20161028] at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java= :671) [130:org.eclipse.jetty.util:9.3.14.v20161028] at org.eclipse.jetty.util.thread.QueuedThreadPool$2.run(QueuedThreadPool.java:= 589) [130:org.eclipse.jetty.util:9.3.14.v20161028] at java.lang.Thread.run(Thread.java:745) [?:?] Caused by: java.lang.NullPointerException at org.apache.aries.tx.control.jpa.xa.impl.JPAEntityManagerProviderFactoryImpl= $EnlistingDataSource.lambda$getConnection$4(JPAEntityManagerProviderFactory= Impl.java:193) ~[?:?] at org.apache.aries.tx.control.jpa.xa.impl.JPAEntityManagerProviderFactoryImpl= $EnlistingDataSource.enlistedConnection(JPAEntityManagerProviderFactoryImpl= .java:230) ~[?:?] ... 78 more Best, Alexander >>>=20 Hi Alexander, So what you=E2=80=99re doing is passing a fully configured EntityManagerFac= tory to the resource provider factory. If you create the provider this way then you are responsible for setting up all of the EntityManagerFactory=E2=80=99s configuration, including how it=E2=80=99s = going to integrate with transaction control. For local transactions there is nothing to integrate with , but in the general case this is act ually 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/ed8dbc79758766081203056cff27eb0bcbd7ef= b3/tx-control/tx-control-providers/jpa/tx-control-provider-jpa-xa/src/main/= java/org/apache/aries/tx/control/jpa/xa/impl/JPAEntityManagerProviderFactor= yImpl.java#L122) does quite a bit less setup on your behalf than the configuration-driven version does ( https://github.com/apache/aries/blob/ed8dbc79758766081203056cff27eb0bcbd7ef= b3/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=20 provide a factory configuration for the =E2=80=9Corg.apache.aries.tx.control.jpa.xa=E2=80=9D pid containing =E2=80=9Cosgi.unit.name=3D=E2=80=9D = and any necessary datasource configuration (i.e. that=E2=80=99s 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-u= sing-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, wrote: Hi Tim, I use a JPAEntityManagerProviderFactory (providerFactory) which I inject as a service reference into my repository class.=20 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 =3D 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. >>>=20 Hi Alexander, Do you have a code example of how you=E2=80=99re 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=E2=80=99s = 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 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 : Hello. I'm trying to get tx-control with XA transactions running (local is working).=20 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 h ibernate-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. --=20 ------------------------ Guillaume Nodet --=__Part3E06D3F5.1__= Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Content-Description: HTML =0A=0A=0A=0A
Thanks Tim for = the update.

I tried the approach with providing a = factory config in karaf.dir/etc/org.apache.aries.tx.control.jpa.xa.cfg = with config as:
osgi.unit.name=3DDSContext2
osgi.jdbc.driver.c= lass=3Dorg.h2.Driver
url=3Djdbc:h2:mem:article
user=3Dsa
password= =3D

whilst having a mininmal persistence.xml = like:
<persistence-unit name=3D"DSContext" >
  = ;      <properties>
   &nb= sp;        <property name=3D"hibernat= e.dialect" value=3D"org.hibernate.dialect.H2Dialect" />
  &= nbsp;     </properties>
    = </persistence-unit>

(without the dialect I = see another exception; Access to DialectResolutionInfo cannot be null when = 'hibernate.dialect' not set).

Now I get further = in the process (transaction enlistment works) but when actually accessing = the database, the entity manager throws a NPE while trying to open the = connection. In JPAEntityManagerProviderFactoryImpl.EnlistingDataSource.enli= stedConnection() while calling supplier.call, the supplier.delegate member = is null:

org.osgi.service.transaction.control.Tran= sactionException: There was a problem getting hold of a database connection=
        at org.apache.aries.tx.contr= ol.jpa.xa.impl.JPAEntityManagerProviderFactoryImpl$EnlistingDataSource.enli= stedConnection(JPAEntityManagerProviderFactoryImpl.java:241) ~[?:?]
&nbs= p;       at org.apache.aries.tx.control.jpa.x= a.impl.JPAEntityManagerProviderFactoryImpl$EnlistingDataSource.getConnectio= n(JPAEntityManagerProviderFactoryImpl.java:193) ~[?:?]
   = ;     at org.hibernate.engine.jdbc.connections.internal= .DatasourceConnectionProviderImpl.getConnection(DatasourceConnectionProvide= rImpl.java:122) ~[?:?]
        at = org.hibernate.internal.NonContextualJdbcConnectionAccess.obtainConnection(N= onContextualJdbcConnectionAccess.java:35) ~[?:?]
    = ;    at org.hibernate.resource.jdbc.internal.LogicalConnecti= onManagedImpl.acquireConnectionIfNeeded(LogicalConnectionManagedImpl.java:9= 9) ~[?:?]
        at org.hibernate.re= source.jdbc.internal.LogicalConnectionManagedImpl.getPhysicalConnection(Log= icalConnectionManagedImpl.java:129) ~[?:?]
     = ;   at org.hibernate.engine.jdbc.internal.StatementPreparerImpl.c= onnection(StatementPreparerImpl.java:47) ~[?:?]
    =     at org.hibernate.engine.jdbc.internal.StatementPreparerI= mpl$5.doPrepare(StatementPreparerImpl.java:146) ~[?:?]
   = ;     at org.hibernate.engine.jdbc.internal.StatementPr= eparerImpl$StatementPreparationTemplate.prepareStatement(StatementPreparerI= mpl.java:172) ~[?:?]
        at = org.hibernate.engine.jdbc.internal.StatementPreparerImpl.prepareQueryStatem= ent(StatementPreparerImpl.java:148) ~[?:?]
     = ;   at org.hibernate.loader.Loader.prepareQueryStatement(Loader.j= ava:1940) ~[?:?]
        at = org.hibernate.loader.Loader.executeQueryStatement(Loader.java:1909) = ~[?:?]
        at org.hibernate.loade= r.Loader.executeQueryStatement(Loader.java:1887) ~[?:?]
  &nbs= p;     at org.hibernate.loader.Loader.doQuery(Loader.ja= va:932) ~[?:?]
        at org.hiberna= te.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:349) = ~[?:?]
        at org.hibernate.loade= r.Loader.doList(Loader.java:2615) ~[?:?]
     &= nbsp;  at org.hibernate.loader.Loader.doList(Loader.java:2598) = ~[?:?]
        at org.hibernate.loade= r.Loader.listIgnoreQueryCache(Loader.java:2430) ~[?:?]
   = ;     at org.hibernate.loader.Loader.list(Loader.java:2= 425) ~[?:?]
        at org.hibernate.= loader.custom.CustomLoader.list(CustomLoader.java:335) ~[?:?]
 &nbs= p;      at org.hibernate.internal.SessionImpl.list= CustomQuery(SessionImpl.java:2153) ~[?:?]
     =    at org.hibernate.internal.AbstractSharedSessionContract.list(A= bstractSharedSessionContract.java:991) ~[?:?]
    &n= bsp;   at org.hibernate.query.internal.NativeQueryImpl.doList(Nat= iveQueryImpl.java:147) ~[?:?]
       = at org.hibernate.query.internal.AbstractProducedQuery.list(AbstractProduce= dQuery.java:1410) ~[?:?]
        at = org.hibernate.query.internal.AbstractProducedQuery.getSingleResult(Abstract= ProducedQuery.java:1459) ~[?:?]
      &nbs= p; at com.brodos.ds.persistence.h2.TestRepositoryImpl.lambda$checkHealth$0(= TestRepositoryImpl.java:47) ~[?:?]
      &= nbsp; at org.apache.aries.tx.control.service.common.impl.AbstractTransactio= nControlImpl$TransactionBuilderImpl.doWork(AbstractTransactionControlImpl.j= ava:161) [241:tx-control-service-xa:0.0.3]
     = ;   at org.apache.aries.tx.control.service.common.impl.AbstractTr= ansactionControlImpl$TransactionBuilderImpl.required(AbstractTransactionCon= trolImpl.java:84) [241:tx-control-service-xa:0.0.3]
   &n= bsp;    at org.apache.aries.tx.control.service.common.impl.A= bstractTransactionControlImpl.required(AbstractTransactionControlImpl.java:= 263) [241:tx-control-service-xa:0.0.3]
     &nb= sp;  at com.brodos.ds.persistence.h2.TestRepositoryImpl.checkHealth(Te= stRepositoryImpl.java:44) [160:com.brodos.example.ds.DSContext-infrastructu= re:1.0.0.SNAPSHOT]
        at = com.brodos.ds.service.impl.MainHealthCheck.checkHealth(MainHealthCheck.java= :29) [209:com.brodos.example.ds.DSContext-service:1.0.0.SNAPSHOT]
 =        at com.brodos.ds.application.boundary.= impl.HealthCheckImpl.checkHealth(HealthCheckImpl.java:37) [212:com.brodos.e= xample.ds.DSContext-application:1.0.0.SNAPSHOT]
    =     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native = Method) ~[?:?]
        at sun.reflect= .NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) = ~[?:?]
        at sun.reflect.Delegat= ingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) = ~[?:?]
        at java.lang.reflect.M= ethod.invoke(Method.java:497) ~[?:?]
      = ;  at org.apache.cxf.service.invoker.AbstractInvoker.performInvocation= (AbstractInvoker.java:180) [84:org.apache.cxf.cxf-core:3.1.12]
 &nb= sp;      at org.apache.cxf.service.invoker.Abstrac= tInvoker.invoke(AbstractInvoker.java:96) [84:org.apache.cxf.cxf-core:3.1.12= ]
        at org.apache.cxf.jaxrs.JAX= RSInvoker.invoke(JAXRSInvoker.java:189) [85:org.apache.cxf.cxf-rt-frontend-= jaxrs:3.1.12]
        at org.apache.c= xf.jaxrs.JAXRSInvoker.invoke(JAXRSInvoker.java:99) [85:org.apache.cxf.cxf-r= t-frontend-jaxrs:3.1.12]
        at = org.apache.cxf.interceptor.ServiceInvokerInterceptor$1.run(ServiceInvokerIn= terceptor.java:59) [84:org.apache.cxf.cxf-core:3.1.12]
   = ;     at org.apache.cxf.interceptor.ServiceInvokerInter= ceptor.handleMessage(ServiceInvokerInterceptor.java:96) [84:org.apache.cxf.= cxf-core:3.1.12]
        at = org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChai= n.java:308) [84:org.apache.cxf.cxf-core:3.1.12]
    =     at org.apache.cxf.transport.ChainInitiationObserver.onMe= ssage(ChainInitiationObserver.java:121) [84:org.apache.cxf.cxf-core:3.1.12]=
        at org.apache.cxf.transport.= http.AbstractHTTPDestination.invoke(AbstractHTTPDestination.java:263) = [92:org.apache.cxf.cxf-rt-transports-http:3.1.12]
   &nbs= p;    at org.apache.cxf.transport.servlet.ServletController.= invokeDestination(ServletController.java:234) [92:org.apache.cxf.cxf-rt-tra= nsports-http:3.1.12]
        at = org.apache.cxf.transport.servlet.ServletController.invoke(ServletController= .java:208) [92:org.apache.cxf.cxf-rt-transports-http:3.1.12]
  = ;      at org.apache.cxf.transport.servlet.Servlet= Controller.invoke(ServletController.java:160) [92:org.apache.cxf.cxf-rt-tra= nsports-http:3.1.12]
        at = org.apache.cxf.transport.servlet.CXFNonSpringServlet.invoke(CXFNonSpringSer= vlet.java:189) [92:org.apache.cxf.cxf-rt-transports-http:3.1.12]
 &= nbsp;      at org.apache.cxf.transport.servlet.Abs= tractHTTPServlet.handleRequest(AbstractHTTPServlet.java:299) [92:org.apache= .cxf.cxf-rt-transports-http:3.1.12]
      =   at org.apache.cxf.transport.servlet.AbstractHTTPServlet.doGet(Abstra= ctHTTPServlet.java:223) [92:org.apache.cxf.cxf-rt-transports-http:3.1.12]        at javax.servlet.http.HttpServ= let.service(HttpServlet.java:687) [69:javax.servlet-api:3.1.0]
 &nb= sp;      at org.apache.cxf.transport.servlet.Abstr= actHTTPServlet.service(AbstractHTTPServlet.java:274) [92:org.apache.cxf.cxf= -rt-transports-http:3.1.12]
        = at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:845) = [128:org.eclipse.jetty.servlet:9.3.14.v20161028]
    = ;    at org.eclipse.jetty.servlet.ServletHandler.doHandle(Se= rvletHandler.java:584) [128:org.eclipse.jetty.servlet:9.3.14.v20161028]
=         at org.ops4j.pax.web.service.jet= ty.internal.HttpServiceServletHandler.doHandle(HttpServiceServletHandler.ja= va:71) [150:org.ops4j.pax.web.pax-web-jetty:6.0.6]
   &nb= sp;    at org.eclipse.jetty.server.handler.ScopedHandler.han= dle(ScopedHandler.java:143) [127:org.eclipse.jetty.server:9.3.14.v20161028]=
        at org.eclipse.jetty.securit= y.SecurityHandler.handle(SecurityHandler.java:548) [125:org.eclipse.jetty.s= ecurity:9.3.14.v20161028]
        at = org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.jav= a:226) [127:org.eclipse.jetty.server:9.3.14.v20161028]
   = ;     at org.eclipse.jetty.server.handler.ContextHandle= r.doHandle(ContextHandler.java:1180) [127:org.eclipse.jetty.server:9.3.14.v= 20161028]
        at org.ops4j.pax.we= b.service.jetty.internal.HttpServiceContext.doHandle(HttpServiceContext.jav= a:284) [150:org.ops4j.pax.web.pax-web-jetty:6.0.6]
   &nb= sp;    at org.eclipse.jetty.servlet.ServletHandler.doScope(S= ervletHandler.java:512) [128:org.eclipse.jetty.servlet:9.3.14.v20161028]        at org.eclipse.jetty.server.ses= sion.SessionHandler.doScope(SessionHandler.java:185) [127:org.eclipse.jetty= .server:9.3.14.v20161028]
        at = org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java= :1112) [127:org.eclipse.jetty.server:9.3.14.v20161028]
   = ;     at org.eclipse.jetty.server.handler.ScopedHandler= .handle(ScopedHandler.java:141) [127:org.eclipse.jetty.server:9.3.14.v20161= 028]
        at org.ops4j.pax.web.ser= vice.jetty.internal.JettyServerHandlerCollection.handle(JettyServerHandlerC= ollection.java:80) [150:org.ops4j.pax.web.pax-web-jetty:6.0.6]
 &nb= sp;      at org.eclipse.jetty.server.handler.Handl= erWrapper.handle(HandlerWrapper.java:134) [127:org.eclipse.jetty.server:9.3= .14.v20161028]
        at org.eclipse= .jetty.server.Server.handle(Server.java:534) [127:org.eclipse.jetty.server:= 9.3.14.v20161028]
        at = org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:320) = [127:org.eclipse.jetty.server:9.3.14.v20161028]
    =     at org.eclipse.jetty.server.HttpConnection.onFillable(Ht= tpConnection.java:251) [127:org.eclipse.jetty.server:9.3.14.v20161028]
&= nbsp;       at org.eclipse.jetty.io.AbstractC= onnection$ReadCallback.succeeded(AbstractConnection.java:273) [119:org.ecli= pse.jetty.io:9.3.14.v20161028]
       = ; at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:95) = [119:org.eclipse.jetty.io:9.3.14.v20161028]
    &nbs= p;   at org.eclipse.jetty.io.SelectChannelEndPoint$2.run(SelectCh= annelEndPoint.java:93) [119:org.eclipse.jetty.io:9.3.14.v20161028]
 = ;       at org.eclipse.jetty.util.thread.stra= tegy.ExecuteProduceConsume.executeProduceConsume(ExecuteProduceConsume.java= :303) [130:org.eclipse.jetty.util:9.3.14.v20161028]
   &n= bsp;    at org.eclipse.jetty.util.thread.strategy.ExecutePro= duceConsume.produceConsume(ExecuteProduceConsume.java:148) [130:org.eclipse= .jetty.util:9.3.14.v20161028]
       = at org.eclipse.jetty.util.thread.strategy.ExecuteProduceConsume.run(Execut= eProduceConsume.java:136) [130:org.eclipse.jetty.util:9.3.14.v20161028]
=         at org.eclipse.jetty.util.thread= .QueuedThreadPool.runJob(QueuedThreadPool.java:671) [130:org.eclipse.jetty.= util:9.3.14.v20161028]
        at = org.eclipse.jetty.util.thread.QueuedThreadPool$2.run(QueuedThreadPool.java:= 589) [130:org.eclipse.jetty.util:9.3.14.v20161028]
   &nb= sp;    at java.lang.Thread.run(Thread.java:745) [?:?]
Cau= sed by: java.lang.NullPointerException
     &nb= sp;  at org.apache.aries.tx.control.jpa.xa.impl.JPAEntityManagerProvid= erFactoryImpl$EnlistingDataSource.lambda$getConnection$4(JPAEntityManagerPr= oviderFactoryImpl.java:193) ~[?:?]
      &= nbsp; at org.apache.aries.tx.control.jpa.xa.impl.JPAEntityManagerProviderFa= ctoryImpl$EnlistingDataSource.enlistedConnection(JPAEntityManagerProviderFa= ctoryImpl.java:230) ~[?:?]
        = ... 78 more

Best, Alexander


>>> =
Hi Alexander,

So what = you=E2=80=99re doing is passing a fully configured EntityManagerFact= ory to the resource provider factory. If you create the provider this way = then you are responsible for setting up all of the EntityManagerFact= ory=E2=80=99s configuration, including how it=E2=80=99s 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 does quite a bit less setup on = your behalf than the configuration-driven version does. If = you were to 
provide a factory configuration for the = =E2=80=9Corg.apache.aries.tx.control.jpa.xa=E2=80=9D pid containing = =E2=80=9Cosgi.unit.name=3D<your persistence unit=E2=80=99s name>=E2= =80=9D and any necessary datasource configuration (i.e. that=E2=80=99s not = coming from the persistence xml) then you could inject the JPAEntityManager= Provider directly as a service.

More documentation= about configuration-driven resources for Aries Tx-Control is = available at http://aries.apa= che.org/modules/tx-control/xaJPA.html#creating-a-resource-using-a-factory-c= onfiguration

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:
=0A=0A=0A= =0A
Hi Tim,

I use a JPAEntityManagerProvi= derFactory (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 =3D 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()
&nbs= p;            &= nbsp;  .required(
        &= nbsp;           &nbs= p;   () -> repo.store(article));

Best= , Alexander.


>>>

Hi = Alexander,

Do you have a code example of how = you=E2=80=99re 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=E2=80=99s 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> = wrote:

F= wiw, 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.
An= yway, I'd gladly support you if you go to the aries mailing list to raise = this point !

2= 017-09-13 9:52 GMT+02:00 <alexander.sahler@brodos.de>:
=0A=0A=0A=0A
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 RecoveryWorkAroundTransaction= Manager (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.
=0A<= /blockquote>



--
-----------------= -------
Guillaume Nodet

=0A
=0A

=0A

--=__Part3E06D3F5.1__=-- --=__Part3E06D3F5.0__=--