From user-return-18587-archive-asf-public=cust-asf.ponee.io@karaf.apache.org Fri May 18 16:55:27 2018 Return-Path: X-Original-To: archive-asf-public@cust-asf.ponee.io Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx-eu-01.ponee.io (Postfix) with SMTP id F18F5180648 for ; Fri, 18 May 2018 16:55:25 +0200 (CEST) Received: (qmail 82321 invoked by uid 500); 18 May 2018 14:55:24 -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 82310 invoked by uid 99); 18 May 2018 14:55:24 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd2-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 18 May 2018 14:55:24 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd2-us-west.apache.org (ASF Mail Server at spamd2-us-west.apache.org) with ESMTP id 4B3881A009C for ; Fri, 18 May 2018 14:55:24 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd2-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 1.281 X-Spam-Level: * X-Spam-Status: No, score=1.281 tagged_above=-999 required=6.31 tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, HTML_MESSAGE=2, KAM_SHORT=0.001, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01] autolearn=disabled Authentication-Results: spamd2-us-west.apache.org (amavisd-new); dkim=pass (2048-bit key) header.d=envieta-com.20150623.gappssmtp.com Received: from mx1-lw-us.apache.org ([10.40.0.8]) by localhost (spamd2-us-west.apache.org [10.40.0.9]) (amavisd-new, port 10024) with ESMTP id BhBJLzW0PPDY for ; Fri, 18 May 2018 14:55:17 +0000 (UTC) Received: from mail-qt0-f178.google.com (mail-qt0-f178.google.com [209.85.216.178]) by mx1-lw-us.apache.org (ASF Mail Server at mx1-lw-us.apache.org) with ESMTPS id C513E5F21E for ; Fri, 18 May 2018 14:55:16 +0000 (UTC) Received: by mail-qt0-f178.google.com with SMTP id f1-v6so10602771qtj.6 for ; Fri, 18 May 2018 07:55:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=envieta-com.20150623.gappssmtp.com; s=20150623; h=from:mime-version:subject:date:references:to:in-reply-to:message-id; bh=qj9K3RqlsBwfYMLnGShc/xocD7lEOAmbkmeXu5A9Fjo=; b=Gp95O9ciktz4ipLVX4dYNUhhACUP3uEFbdCc1ef2MNhnBbktl4VhEVFokKUXeyGc3V 9uH8aTfg73Z6hVmQ1pF4A2CEx9w7/7mOyCDv8YiYOD0MpZlsKB2bD4VtQsdwX+NdCyoP BB9Hwa/s3m4KFfCDLzX4AHOSf/8xuubVKFKuB9lag4GjTqJgV5/RTgxDxWJWX0vej9rb 2U+vNgBqdlIi9ItKF4Snv2bC50HoXEka9N/KVcAjQ7XCt3YwEyMyfR3ljJs4pD5Sr+wn S0YlYw2ZYPTD5jK8013cf5uTz6SqPcrYUErSCCWAFx76cFJwPzln4S4ObRHULjxukWRn 2tKA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:mime-version:subject:date:references:to :in-reply-to:message-id; bh=qj9K3RqlsBwfYMLnGShc/xocD7lEOAmbkmeXu5A9Fjo=; b=cpxuZ748mUZhPgE4UxGLVvM5RsTWtC+++KPNrz0iAF4C/0zB8OISoPraRlD+5YIH7t nbRgxbrIEJ/padg7S+wIOGNFelNdN/8zOeEC0t3mdU6AMF5BHT+D0x5nUPIKdob1W7LT QQgyBR7lpsNDz1K/AdnwDICvYsF/1euuM+AkBQ62MycmzMYh5oUFx/uI3hgXAaKfSb0p lPnwCTBCsU6j5UFks7LJ4+JzoFClSYtJo65nhfk7dhQugH7oODHcULR7CAE3Y5sZPfO7 ZbxbobcDjGlKCohtZVF1BE4H0vLK6d8VR8lvnVPKwjMs+B/mZiN/ZotNvRY1FEAK2iqh IN5w== X-Gm-Message-State: ALKqPwcwSDS2FJHYjh+evZeiHgaUKe2izpvCtEqGtDYYRst30PbYV55l tepWHIFH4RusMJrbpJunZr87gvVqob0833BuEO3IPoUphrij36k9yxkEHvn1x7s2Kcq/vOSYF20 +0IWwO7Ewcvwh21vCEeGJDYclrRvSmjXrUWVLiBZ1kFMtQDwkaZAbIGQlPTZ1KfIsI6EP X-Google-Smtp-Source: AB8JxZpUnV1mwyB+3s+IG4rbTAXp11M3TqvBrdy8Lw+sbpdkK5ILrPAfjp0UHTtXjvhI35RiqFpVzg== X-Received: by 2002:a0c:944f:: with SMTP id i15-v6mr9079642qvi.215.1526655316058; Fri, 18 May 2018 07:55:16 -0700 (PDT) Received: from [10.0.0.239] (pool-71-121-235-201.bltmmd.fios.verizon.net. [71.121.235.201]) by smtp.gmail.com with ESMTPSA id t13-v6sm5804839qte.77.2018.05.18.07.55.14 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 18 May 2018 07:55:15 -0700 (PDT) From: Alex Soto Content-Type: multipart/alternative; boundary="Apple-Mail=_13D25162-4109-4D05-9544-BC1EE46E63BD" Mime-Version: 1.0 (Mac OS X Mail 11.3 \(3445.6.18\)) Subject: Re: MariaDB/JPA Transaction rollback not working Date: Fri, 18 May 2018 10:55:14 -0400 References: <6089032d-9efa-3243-fe21-e0f0033a4d04@nanthrax.net> <5643B995-B9F1-4E79-A5AB-8D8AC66F6BEB@envieta.com> <811b01ee-5b74-e294-d20f-89954661e415@nanthrax.net> <25A180D1-73AD-463A-8A52-4EBF81A65B28@paremus.com> <635DC926-FFBB-434D-BF45-2CB980954005@paremus.com> <975389E7-1766-42D8-A42D-F096EFFBF408@envieta.com> <821F4411-4742-45D6-8AB5-893D1FC27A9E@paremus.com> <9D1A9178-39AD-4F6F-876D-8AFA838377FE@paremus.com> <553CFABC-6C09-4990-9E33-3C5D2527FA2E@envieta.com> <75DE775F-7D76-40D5-86CA-9F5EC6FDBB1E@paremus.com> To: user@karaf.apache.org In-Reply-To: <75DE775F-7D76-40D5-86CA-9F5EC6FDBB1E@paremus.com> Message-Id: <08BE597F-CC91-4EA6-91D5-FFAA39486414@envieta.com> X-Mailer: Apple Mail (2.3445.6.18) --Apple-Mail=_13D25162-4109-4D05-9544-BC1EE46E63BD Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 Thank you Tim for the very detailed explanation. There are two problems I don=E2=80=99t know how to resolve: 1- BND generates this for my bundle:=20 Require-Capability: = osgi.extender;filter:=3D"(&(osgi.extender=3Dosgi.component)(version>=3D1.3= .0)(!(version>=3D2.0.0)))=E2=80=9D This is because I use the @Component and @Reference annotations. = This is strange, since I should be using OSGi R7, so I am not sure why = it is saying 1.3.0. Now when try to run in Karaf, even though I am = installing scr feature, it fails with unresolved requirement. Since I could not find OSGi R7 in public Maven Repos, I followed = EnRoute depending on: org.osgi.enroute osgi-api 7.0.0-SNAPSHOT pom provided org.osgi.enroute enterprise-api 7.0.0-SNAPSHOT pom provided 2- This is minor, and I see it also in the EnRoute project. While the = Maven build succeeds, Eclipse BND plugin shows 2 errors: The default package '.' is not permitted by the Import-Package syntax. = This can be caused by compile errors in Eclipse because Eclipse creates = valid class files regardless of compile errors. The following package(s) = import from the default package = [org.enquery.encryptedquery.responder.data.service.impl] = (biz.aQute.bnd:bnd-maven-plugin:4.0.0:bnd-process:default:process-classes)= pom.xml /encryptedquery-responder-data line 0 Maven Build = Participant Problem=20 The project was not built since its build path is incomplete. Cannot = find the class file for javax.persistence.EntityManager. Fix the build = path then try building this project encryptedquery-responder-data = Unknown Java Problem =20 Best regards, Alex soto > On May 18, 2018, at 5:23 AM, Tim Ward wrote: >=20 > Hi Alex, >=20 > The bundles you need are listed in the bndrun for the JPA version of = the enRoute application, but as I think you=E2=80=99re using OpenJPA = (rather than Hibernate) it may help to explain things in relation to the = Transaction Control JPA integration test for OpenJPA. I=E2=80=99m sure = that at least some of this will be stuff you already know, but I=E2=80=99m= trying to make sure I give a compete explanation.=20 >=20 > This method defines some extra properties to add to the persistence = unit. It references a couple of open bugs in OpenJPA which may or may = not affect you. It also adds schema generation as OpenJPA does not = support the standard properties from JPA 2.1 = https://github.com/apache/aries-tx-control/blob/master/tx-control-provider= s/jpa/tx-control-jpa-itests/src/test/java/org/apache/aries/tx/control/ites= ts/SimpleOpenJPA_2_4_1_Test.java#L34 = >=20 > This method defines the OpenJPA bundles and their immediate = dependencies. = https://github.com/apache/aries-tx-control/blob/master/tx-control-provider= s/jpa/tx-control-jpa-itests/src/test/java/org/apache/aries/tx/control/ites= ts/SimpleOpenJPA_2_4_1_Test.java#L48 = >=20 > You then need: >=20 > =E2=80=A2 Aries JPA 2.7.0 - this provides the OSGi JPA Service 1.1 RI = (1.1 features are needed by the Aries Tx Control JPA resource provider = to support XA) >=20 > =E2=80=A2 Aries Tx Control Service - either XA or local depending on = whether you need XA Transaction support. For example = https://github.com/apache/aries-tx-control/blob/master/tx-control-provider= s/jpa/tx-control-jpa-itests/src/test/java/org/apache/aries/tx/control/ites= ts/AbstractJPATransactionTest.java#L365 = >=20 > =E2=80=A2 Aries Tx Control JPA resource provider - either XA or local = depending on your needs. Note that you can=E2=80=99t use the XA provider = with the local service, but you can use the local provider with the XA = service (although this doesn=E2=80=99t make a lot of sense to do). For = example = https://github.com/apache/aries-tx-control/blob/master/tx-control-provider= s/jpa/tx-control-jpa-itests/src/test/java/org/apache/aries/tx/control/ites= ts/AbstractJPATransactionTest.java#L377 = >=20 > =E2=80=A2 A JDBC Service implementation supporting your database = driver. H2 supports this natively (which is why it is used in many = examples) but MariaDB does not. Therefore you will need to deploy = PAX-JDBC=E2=80=99s support. See = https://github.com/ops4j/org.ops4j.pax.jdbc/tree/master/pax-jdbc-mariadb = = >=20 > You then have the option of either programmatically assembling your = Resource Provider, or using configuration. Configuration is generally = easier and is what I normally recommend. At that point you need to = create a factory configuration for the relevant PID (it depends on = whether you use the local or XA resource provider, see = https://github.com/apache/aries-tx-control/blob/master/tx-control-provider= s/jpa/tx-control-jpa-itests/src/test/java/org/apache/aries/tx/control/ites= ts/AbstractJPATransactionTest.java#L175 = ) >=20 > The necessary configuration properties are: >=20 > =E2=80=A2 url - the JDBC URL for your database=20 > =E2=80=A2 osgi.jdbc.driver.class - the database driver class name, in = your case org.mariadb.jdbc.Driver > =E2=80=A2 osgi.unit.name - the name of your persistence unit=20 >=20 > The result of this configuration will be a JPAEntityManagerProvider = service registered in the service registry (using your = EntityManagerFactoryBuilder and the MariaDB DataSourceFactory). You can = then Inject that service into your code and combine it with the = TransactionControl service to make a thread safe EntityManager that you = can use in all your requests (just like the enRoute example does).=20 >=20 > I hope this helps, >=20 > Tim >=20 > Sent from my iPhone >=20 > On 17 May 2018, at 22:46, Alex Soto > wrote: >=20 >> Thanks Tim,=20 >>=20 >> I was using branch R7, changed to master, it builds now. >>=20 >> Now I have updated my project to OSGi 7 with Transaction Control, how = do I deploy to Karaf? >> i.e., what bundles/features do I need? >>=20 >>=20 >> Best regards, >> Alex soto >>=20 >>=20 >>=20 >>=20 >>> On May 17, 2018, at 2:08 PM, Tim Ward > wrote: >>>=20 >>> Hi Alex, >>>=20 >>> Bnd 4.0.0 was only released last Sunday, but this should have been = changed yesterday in this commit = https://github.com/osgi/osgi.enroute/commit/9f9857c3d317cd08a7aaf7327c1904= 676299f9ee = to make sure enRoute kept building.=20 >>>=20 >>> EnRoute is automatically pushed to the sonatype OSGi nexus = repository, so is it possible that you=E2=80=99re running offline, or = firewalled from the repo? You should be able to force snapshot updates = from the Maven command line.=20 >>>=20 >>> Best Regards, >>>=20 >>> Tim >>>=20 >>> Sent from my iPhone >>>=20 >>> On 17 May 2018, at 18:26, Alex Soto > wrote: >>>=20 >>>> Allright, I am trying to follow the EnRoute tutorial. >>>>=20 >>>> I am getting this error: >>>>=20 >>>> [ERROR] Plugin biz.aQute.bnd:bnd-maven-plugin:4.0.0-SNAPSHOT or one = of its dependencies could not be resolved: Could not find artifact = biz.aQute.bnd:bnd-maven-plugin:jar:4.0.0-SNAPSHOT in Bnd Snapshots = (https://bndtools.ci.cloudbees.com/job/bnd.master/lastSuccessfulBuild/arti= fact/dist/bundles/ = ) -> [Help 1] >>>>=20 >>>>=20 >>>> Any idea (time frame) when this will move from SNAPSHOT = dependencies? >>>>=20 >>>>=20 >>>> Best regards, >>>> Alex soto >>>>=20 >>>>=20 >>>>=20 >>>>=20 >>>>> On May 17, 2018, at 11:08 AM, Tim Ward > wrote: >>>>>=20 >>>>> It is highly unlikely that you=E2=80=99ll hit the same issues. The = transaction control resource provider uses the DataSourceFactory = directly to create a DataSource (either progamatically using a factory = service or via config admin) that enlists itself in the ongoing = transaction. This means that the answer to your question is =E2=80=9Cwith = Transaction Control you don=E2=80=99t have to do that because it does it = automatically=E2=80=9D >>>>>=20 >>>>> If you want to use XA transactions then the only requirement is = that the DataSourceFactory can produce an XADataSource, otherwise it = just uses the standard JDBC API to commit/rollback. If your = DataSourceFactory doesn=E2=80=99t support XA then use the local resource = provider implementation. >>>>>=20 >>>>> Best Regards, >>>>>=20 >>>>> Tim >>>>>=20 >>>>> Sent from my iPhone >>>>>=20 >>>>> On 17 May 2018, at 15:17, Alex Soto > wrote: >>>>>=20 >>>>>> I will take a look at these examples. >>>>>>=20 >>>>>> However, I think that if I cannot get a MariaDB DataSource that = supports transactions, then it will still not work, right? >>>>>> If the examples use H2 database, I still may get different = results when I change to MariaDB, and I will find myself in the same = spot as of now. >>>>>>=20 >>>>>> So, the question remains about what is the correct way how to = register a transaction aware MariaDB DataSource. >>>>>>=20 >>>>>>=20 >>>>>> Best regards, >>>>>> Alex soto >>>>>>=20 >>>>>>=20 >>>>>>=20 >>>>>>=20 >>>>>>> On May 17, 2018, at 1:46 AM, Tim Ward > wrote: >>>>>>>=20 >>>>>>> The best place to start when looking for OSGi R7 examples is the = enRoute Project. It contains Maven Archetypes, examples and worked = tutorials for building applications using R7 specifications.=20 >>>>>>>=20 >>>>>>> https://enroute.osgi.org >>>>>>>=20 >>>>>>> Most of the projects in use are just new versions of long = established OSGi implementations from Aries and Felix. The majority of = them are already released and in Maven Central. Those that are still in = the process of releasing (pretty much just the JAX-RS whiteboard) are = available in the Apache Snapshots repository. I am not aware of any = implementations that require R7 framework features, so all of them = should run on Karaf. >>>>>>>=20 >>>>>>> Best Regards, >>>>>>>=20 >>>>>>> Tim >>>>>>>=20 >>>>>>> Sent from my iPhone >>>>>>>=20 >>>>>>> On 16 May 2018, at 22:25, Alex Soto > wrote: >>>>>>>=20 >>>>>>>> I agree, it s very frustrating and time consuming. Almost = impossible to get it right. >>>>>>>> I may try the OSGi R7, but I am not sure of its adoption level = at this time, availability of bundles, examples, support by Karaf, etc. >>>>>>>>=20 >>>>>>>>=20 >>>>>>>> Anyway, back to my current stack. I only see one DataSource = being registered: >>>>>>>>=20 >>>>>>>> karaf@root()> service:list DataSource >>>>>>>> [javax.sql.DataSource] >>>>>>>> ---------------------- >>>>>>>> databaseName =3D responder >>>>>>>> dataSourceName =3D responder >>>>>>>> osgi.jdbc.driver.name =3D mariadb >>>>>>>> osgi.jndi.service.name =3D responder >>>>>>>> service.bundleid =3D 14 >>>>>>>> service.factoryPid =3D org.ops4j.datasource >>>>>>>> service.id =3D 194 >>>>>>>> service.pid =3D = org.ops4j.datasource.feb33f6d-dc46-4bc7-a417-ad6bdd5a6ee5 >>>>>>>> service.scope =3D singleton >>>>>>>> url =3D jdbc:mariadb:XXXXXX >>>>>>>> Provided by :=20 >>>>>>>> OPS4J Pax JDBC Config (14) >>>>>>>> Used by:=20 >>>>>>>> Data (135) >>>>>>>>=20 >>>>>>>>=20 >>>>>>>> Not sure what to do with this. =20 >>>>>>>> I specified the following in the configuration: >>>>>>>>=20 >>>>>>>> pool=3Dnarayana >>>>>>>> xa=3Dtrue >>>>>>>>=20 >>>>>>>> Best regards, >>>>>>>> Alex soto >>>>>>>>=20 >>>>>>>>=20 >>>>>>>>=20 >>>>>>>>=20 >>>>>>>>> On May 16, 2018, at 4:12 PM, Tim Ward > wrote: >>>>>>>>>=20 >>>>>>>>> The structure of the JNDI name is defined by the JNDI service = specification.=20 >>>>>>>>>=20 >>>>>>>>> osgi:service/[/] >>>>>>>>>=20 >>>>>>>>> So in this case both of your services should be DataSource = instances, but they should have different filters.=20 >>>>>>>>>=20 >>>>>>>>> The important thing is to make sure you have an JTA enlisting = DataSource registered as a service (this isn=E2=80=99t just your normal = DataSource), then to build a filter which selects that. One option for = this is to use the enlistment whiteboard from Aries (not well = documented) = https://github.com/apache/aries/tree/trunk/transaction/transaction-jdbc = >>>>>>>>>=20 >>>>>>>>> This is a non-trivial thing to do, which is why I keep = mentioning Transaction Control which handles the enlistment reliably = without the layers of services.=20 >>>>>>>>>=20 >>>>>>>>> Best Regards, >>>>>>>>>=20 >>>>>>>>> Tim >>>>>>>>>=20 >>>>>>>>> Sent from my iPhone >>>>>>>>>=20 >>>>>>>>> On 16 May 2018, at 21:57, Alex Soto > wrote: >>>>>>>>>=20 >>>>>>>>>> Thank you Tim. >>>>>>>>>>=20 >>>>>>>>>> Any idea what the JNDI names would be? >>>>>>>>>> It is Pax-JDBC creating these JNDI names, so I have no idea. >>>>>>>>>>=20 >>>>>>>>>> =46rom the Karaf console: >>>>>>>>>>=20 >>>>>>>>>>=20 >>>>>>>>>> karaf@root()> jndi:names=20 >>>>>>>>>> JNDI Name =E2=94=82 Class Name >>>>>>>>>> = =E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2= =94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94= =80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=BC=E2=94=80= =E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2= =94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94= =80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80= =E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2= =94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94= =80=E2=94=80=E2=94=80=E2=94=80=E2=94=80 >>>>>>>>>> osgi:service/responder =E2=94=82 = org.mariadb.jdbc.MySQLDataSource >>>>>>>>>> osgi:service/jndi =E2=94=82 = org.apache.karaf.jndi.internal.JndiServiceImpl >>>>>>>>>>=20 >>>>>>>>>>=20 >>>>>>>>>> Best regards, >>>>>>>>>> Alex soto >>>>>>>>>>=20 >>>>>>>>>>=20 >>>>>>>>>>=20 >>>>>>>>>>=20 >>>>>>>>>>> On May 16, 2018, at 3:48 PM, Tim Ward > wrote: >>>>>>>>>>>=20 >>>>>>>>>>> Just looking quickly.=20 >>>>>>>>>>>=20 >>>>>>>>>>> You have the same JNDI name for both JTA and non JTA = DataSources. This is clearly wrong as the DataSource cannot = simultaneously be enlisted in the Transaction and not enlisted. The = comments also indicate a misunderstanding of the purpose of the = non-jta-datasource, which absolutely is used with JTA EntityManagers = (for things like sequence allocation and out of band optimisations). You = really do need to have both and they do need to behave differently. >>>>>>>>>>>=20 >>>>>>>>>>> At a guess your DataSource is not enlisted with the = transaction manager present in the system. This usually happens by = configuring a (otherwise invisible) DataSource wrapper There is nothing = forcing you to make this happen (or checking that it does) hence your = transactions would be broken. This is one of the several reasons I try = to direct people to Transaction Control where the model actively pushes = you toward transactions that actually work, rather than hiding all the = magic behind an annotation. >>>>>>>>>>>=20 >>>>>>>>>>> Hopefully this gives you some clues as to what might be = wrong.=20 >>>>>>>>>>>=20 >>>>>>>>>>> Best Regards, >>>>>>>>>>>=20 >>>>>>>>>>> Tim >>>>>>>>>>>=20 >>>>>>>>>>> Sent from my iPhone >>>>>>>>>>>=20 >>>>>>>>>>>> On 16 May 2018, at 21:34, Jean-Baptiste Onofr=C3=A9 = > wrote: >>>>>>>>>>>>=20 >>>>>>>>>>>> Are you sure about your code ? Flush looks weird to me and = it seems you don't use container managed transaction. >>>>>>>>>>>>=20 >>>>>>>>>>>> Regards >>>>>>>>>>>> JB >>>>>>>>>>>>=20 >>>>>>>>>>>>> On 16/05/2018 21:08, Alex Soto wrote: >>>>>>>>>>>>> Yes, same result. I even tried with Narayana Transaction = Manager, and same result. >>>>>>>>>>>>> Best regards, >>>>>>>>>>>>> Alex soto >>>>>>>>>>>>>> On May 16, 2018, at 2:56 PM, Jean-Baptiste Onofr=C3=A9 = >> wrote: >>>>>>>>>>>>>>=20 >>>>>>>>>>>>>> Same behavior with RequiresNew ? >>>>>>>>>>>>>>=20 >>>>>>>>>>>>>> Regards >>>>>>>>>>>>>> JB >>>>>>>>>>>>>>=20 >>>>>>>>>>>>>>> On 16/05/2018 19:44, Alex Soto wrote: >>>>>>>>>>>>>>> With Karaf version 4.2.0, Rollback is not working with = MariaDB and InnoDB tables. >>>>>>>>>>>>>>> I deployed these features (from Karaf=E2=80=99s = enterprise repository): >>>>>>>>>>>>>>> aries-blueprint >>>>>>>>>>>>>>> transaction >>>>>>>>>>>>>>> jndi >>>>>>>>>>>>>>> jdbc >>>>>>>>>>>>>>> jpa >>>>>>>>>>>>>>> pax-jdbc-mariadb >>>>>>>>>>>>>>> pax-jdbc-config >>>>>>>>>>>>>>> pax-jdbc-pool-dbcp2 >>>>>>>>>>>>>>> hibernate >>>>>>>>>>>>>>> My Data Source is configured in the file = /org.ops4j.datasource-responder.cfg/ >>>>>>>>>>>>>>> osgi.jdbc.driver.name =3D mariadb >>>>>>>>>>>>>>> dataSourceName=3Dresponder >>>>>>>>>>>>>>> url >>>>>>>>>>>>>>> =3D = jdbc:mariadb://mariadb.local:3306/responder?characterEncoding=3DUTF-8&useS= erverPrepStmts=3Dtrue&autocommit=3Dfalse = >>>>>>>>>>>>>>> user=3DXXXX >>>>>>>>>>>>>>> password=3DXXXX >>>>>>>>>>>>>>> databaseName=3Dresponder >>>>>>>>>>>>>>> #Pool Config >>>>>>>>>>>>>>> pool=3Ddbcp2 >>>>>>>>>>>>>>> xa=3Dtrue >>>>>>>>>>>>>>> My persistence.xml: >>>>>>>>>>>>>>> " >>>>>>>>>>>>>>> = xmlns:xsi=3D"http://www.w3.org/2001/XMLSchema-instance = " >>>>>>>>>>>>>>> = xsi:schemaLocation=3D"http://java.sun.com/xml/ns/persistence = >>>>>>>>>>>>>>> = http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd = "> >>>>>>>>>>>>>>> >>>>>>>>>>>>>>> = org.hibernate.jpa.HibernatePersistenceProvider >>>>>>>>>>>>>>> >>>>>>>>>>>>>>> = osgi:service/javax.sql.DataSource/(osgi.jndi.service.name= =3Dresponder) >>>>>>>>>>>>>>> >>>>>>>>>>>>>>> = osgi:service/javax.sql.DataSource/(osgi.jndi.service.= name=3Dresponder) >>>>>>>>>>>>>>> >>>>>>>>>>>>>>> >>>>>>>>>>>>>>> >>>>>>>>>>>>>>> >>>>>>>>>>>>>>> >>>>>>>>>>>>>>> >>>>>>>>>>>>>>> >>>>>>>>>>>>>>> >>>>>>>>>>>>>>> My blueprint.xml: >>>>>>>>>>>>>>> " >>>>>>>>>>>>>>> xmlns:jpa=3D"http://aries.apache.org/xmlns/jpa/v2.0.0 = " >>>>>>>>>>>>>>> = xmlns:tx=3D"http://aries.apache.org/xmlns/transactions/v2.0.0 = " >>>>>>>>>>>>>>> xmlns:xsi=3D"http://www.w3.org/2001/XMLSchema-instance = " >>>>>>>>>>>>>>> = xsi:schemaLocation=3D"http://www.osgi.org/xmlns/blueprint/v1.0.0 = >>>>>>>>>>>>>>> https://osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd = "> >>>>>>>>>>>>>>> >>>>>>>>>>>>>>> >>>>>>>>>>>>>>> >>>>>>>>>>>>>>> >>>>>>>>>>>>>>> >>>>>>>>>>>>>>> For testing I throw exception in my DAO: >>>>>>>>>>>>>>> @Transactional(REQUIRED) >>>>>>>>>>>>>>> public void addUser(User user) { >>>>>>>>>>>>>>> em.persist(user); >>>>>>>>>>>>>>> em.flush(); >>>>>>>>>>>>>>> throw new RuntimeException("On Purpose"); >>>>>>>>>>>>>>> } >>>>>>>>>>>>>>> I expect the record not to be in the table due to = rollback of the transaction, but it still shows up in my database table. >>>>>>>>>>>>>>> Best regards, >>>>>>>>>>>>>>> Alex soto >>>>>>>>>>=20 >>>>>>>>=20 >>>>>>=20 >>>>=20 >>=20 --Apple-Mail=_13D25162-4109-4D05-9544-BC1EE46E63BD Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=utf-8 Thank= you Tim for the very detailed explanation.
There are =  two problems I don=E2=80=99t know how to resolve:

1- BND generates this = for my bundle: 

= Require-Capability: =  osgi.extender;filter:=3D"(&(osgi.extender=3Dosgi.component)(vers= ion>=3D1.3.0)(!(version>=3D2.0.0)))=E2=80=9D

This is = because I use the @Component and @Reference annotations.  This is = strange, since I should be using OSGi R7, so I am not sure why it is = saying 1.3.0.  Now when try to run in Karaf, even though I am = installing scr feature, it fails with unresolved = requirement.

= Since I could not find OSGi R7 in public Maven Repos, I = followed EnRoute depending on:
      <dependency>
      =   <groupId>org.osgi.enroute</groupId>
      =   <artifactId>osgi-api</artifactId>
      =   <version>7.0.0-SNAPSHOT</version>
      =   <type>pom</type>
    =     <scope>provided</scope>
      </dependency>
      <dependency>
      =   <groupId>org.osgi.enroute</groupId>
      =   <artifactId>enterprise-api</artifactId>
      =   <version>7.0.0-SNAPSHOT</version>
      =   <type>pom</type>
    =     <scope>provided</scope>
    =   </dependency>

2- This is minor, and I see it also in = the EnRoute project. While the Maven build succeeds, Eclipse BND plugin = shows 2 errors:

The default package '.' = is not permitted by the Import-Package syntax. This can be caused = by compile errors in Eclipse because Eclipse creates valid = class files regardless of compile errors. The following package(s) = import from the default = package [org.enquery.encryptedquery.responder.data.service.impl] = (biz.aQute.bnd:bnd-maven-plugin:4.0.0:bnd-process:default:process-classes)= = pom.xml /encryptedquery-responder-data line = 0 = Maven Build Participant = Problem 

The = project was not built since its build path is incomplete. Cannot find = the class file for javax.persistence.EntityManager. Fix the build path = then try building this project = encryptedquery-responder-data Unknown Java = Problem

 


Best regards,
Alex soto




On May 18, 2018, at 5:23 AM, Tim Ward <tim.ward@paremus.com> wrote:

Hi Alex,

The bundles you need are listed in the = bndrun for the JPA version of the enRoute application, but as I think = you=E2=80=99re using OpenJPA (rather than Hibernate) it may help to = explain things in relation to the Transaction Control JPA integration = test for OpenJPA. I=E2=80=99m sure that at least some of this will be = stuff you already know, but I=E2=80=99m trying to make sure I give a = compete explanation. 

This method defines some extra properties to add to the = persistence unit. It references a couple of open bugs in OpenJPA which = may or may not affect you. It also adds schema generation as OpenJPA = does not support the standard properties from JPA 2.1 https://github.com/apache/aries-tx-control/blob/master/tx-contr= ol-providers/jpa/tx-control-jpa-itests/src/test/java/org/apache/aries/tx/c= ontrol/itests/SimpleOpenJPA_2_4_1_Test.java#L34

This method defines the OpenJPA bundles and their immediate = dependencies. https://github.com/apache/aries-tx-control/blob/master/tx-contr= ol-providers/jpa/tx-control-jpa-itests/src/test/java/org/apache/aries/tx/c= ontrol/itests/SimpleOpenJPA_2_4_1_Test.java#L48

You then need:

=E2=80=A2 Aries JPA = 2.7.0 - this provides the OSGi JPA Service 1.1 RI (1.1 features are = needed by the Aries Tx Control JPA resource provider to support = XA)


=E2=80=A2 Aries Tx = Control JPA resource provider - either XA or local depending on your = needs. Note that you can=E2=80=99t use the XA provider with the local = service, but you can use the local provider with the XA service = (although this doesn=E2=80=99t make a lot of sense to do). For = example https://github.com/apache/aries-tx-control/blob/master/tx-contr= ol-providers/jpa/tx-control-jpa-itests/src/test/java/org/apache/aries/tx/c= ontrol/itests/AbstractJPATransactionTest.java#L377

=E2=80=A2 A JDBC Service = implementation supporting your database driver. H2 supports this = natively (which is why it is used in many examples) but MariaDB does = not. Therefore you will need to deploy PAX-JDBC=E2=80=99s support. = See https://github.com/ops4j/org.ops4j.pax.jdbc/tree/master/pax-jdb= c-mariadb

You then have the option of either programmatically = assembling your Resource Provider, or using configuration. Configuration = is generally easier and is what I normally recommend. At that point you = need to create a factory configuration for the relevant PID (it depends = on whether you use the local or XA resource provider, see https://github.com/apache/aries-tx-control/blob/master/tx-contr= ol-providers/jpa/tx-control-jpa-itests/src/test/java/org/apache/aries/tx/c= ontrol/itests/AbstractJPATransactionTest.java#L175)

The necessary configuration properties = are:

=E2=80=A2 = url - the JDBC URL for your database 
=E2=80=A2 = osgi.jdbc.driver.class - the database driver class name, in your = case org.mariadb.jdbc.Driver
=E2=80=A2 = osgi.unit.name - the name of your persistence = unit 

The result of this configuration will be a = JPAEntityManagerProvider service registered in the service registry = (using your EntityManagerFactoryBuilder and the MariaDB = DataSourceFactory). You can then Inject that service into your code and = combine it with the TransactionControl service to make a thread safe = EntityManager that you can use in all your requests (just like the = enRoute example does). 

I hope this helps,

Tim

Sent from my iPhone

On 17 = May 2018, at 22:46, Alex Soto <alex.soto@envieta.com> wrote:

Thanks Tim, 

I was using branch R7, changed to = master, it builds now.

Now I have updated my project to OSGi 7 with Transaction = Control, how do I deploy to Karaf?
i.e., what = bundles/features do I need?


Best = regards,
Alex soto




On May 17, 2018, at 2:08 PM, Tim Ward <tim.ward@paremus.com> wrote:

Hi Alex,

Bnd 4.0.0 was only released last = Sunday, but this should have been changed yesterday in this = commit https://github.com/osgi/osgi.enroute/commit/9f9857c3d317cd08a7a= af7327c1904676299f9ee to make sure enRoute kept = building. 

EnRoute is automatically pushed to the sonatype OSGi nexus = repository, so is it possible that you=E2=80=99re running offline, or = firewalled from the repo? You should be able to force snapshot updates = from the Maven command line. 

Best Regards,

Tim

Sent from my iPhone

On 17 = May 2018, at 18:26, Alex Soto <alex.soto@envieta.com> wrote:

Allright,  I am trying to follow the EnRoute = tutorial.

I am = getting this error:

[ERROR] Plugin biz.aQute.bnd:bnd-maven-plugin:4.0.0-SNAPSHOT = or one of its dependencies could not be resolved: Could not find = artifact biz.aQute.bnd:bnd-maven-plugin:jar:4.0.0-SNAPSHOT in Bnd = Snapshots (https://bndtools.ci.cloudbees.com/job/bnd.master/lastSuccessful= Build/artifact/dist/bundles/) -> [Help 1]


Any = idea (time frame) when this will move from SNAPSHOT = dependencies?


Best = regards,
Alex soto




On May 17, 2018, at 11:08 AM, Tim Ward <tim.ward@paremus.com> wrote:

It is highly unlikely that = you=E2=80=99ll hit the same issues. The transaction control resource = provider uses the DataSourceFactory directly to create a DataSource = (either progamatically using a factory service or via config admin) that = enlists itself in the ongoing transaction. This means that the answer to = your question is =E2=80=9Cwith Transaction Control you don=E2=80=99t = have to do that because it does it automatically=E2=80=9D

If you want to use XA = transactions then the only requirement is that the DataSourceFactory can = produce an XADataSource, otherwise it just uses the standard JDBC API to = commit/rollback. If your DataSourceFactory doesn=E2=80=99t support XA = then use the local resource provider implementation.

Best Regards,

Tim

Sent from my iPhone

On 17 May 2018, at 15:17, Alex Soto <alex.soto@envieta.com> wrote:

I will take a look at these examples.

However, I think that if = I cannot get a MariaDB DataSource that supports transactions, then it = will still not work, right?
If the examples use H2 = database, I still may get different results when I change to MariaDB, = and I will find myself in the same spot as of now.

So, the question remains = about what is the correct way how to register a transaction aware = MariaDB DataSource.


Best = regards,
Alex soto




On May 17, 2018, at 1:46 AM, Tim Ward <tim.ward@paremus.com> wrote:

The best place to start when = looking for OSGi R7 examples is the enRoute Project. It contains Maven = Archetypes, examples and worked tutorials for building applications = using R7 specifications. 


Most of the projects in use are just = new versions of long established OSGi implementations from Aries and = Felix. The majority of them are already released and in Maven Central. = Those that are still in the process of releasing (pretty much just the = JAX-RS whiteboard) are available in the Apache Snapshots repository. I = am not aware of any implementations that require R7 framework features, = so all of them should run on Karaf.

Best Regards,

Tim

Sent from my iPhone

On 16 = May 2018, at 22:25, Alex Soto <alex.soto@envieta.com> wrote:

I agree, it s very frustrating and time = consuming. Almost impossible to get it right.
I may try = the OSGi R7, but I am not sure of its adoption level at this time, = availability of bundles, examples, support by Karaf, etc.


Anyway, back to my current stack.  I only see one = DataSource being registered:

karaf@root()> service:list DataSource
[javax.sql.DataSource]
----------------------
 databaseName =3D responder
 dataSourceName =3D responder
 osgi.jdbc.driver.name =3D mariadb
 osgi.jndi.service.name =3D responder
 service.bundleid =3D 14
 service.factoryPid =3D org.ops4j.datasource
 service.id = =3D 194
 service.pid =3D = org.ops4j.datasource.feb33f6d-dc46-4bc7-a417-ad6bdd5a6ee5
 service.scope =3D singleton
 url =3D = jdbc:mariadb:XXXXXX
Provided by : 
 OPS4J Pax JDBC Config (14)
Used = by: 
 Data (135)


Not sure what to do with this.  
I = specified the following in the configuration:

pool=3Dnarayana
xa=3Dtrue

Best = regards,
Alex soto




On May 16, 2018, at 4:12 PM, Tim Ward <tim.ward@paremus.com> wrote:

The structure of the JNDI name = is defined by the JNDI service specification. 

osgi:service/<interface = name>[/<filter>]

So in this case both of your services should be DataSource = instances, but they should have different filters. 

The important thing is = to make sure you have an JTA enlisting DataSource registered as a = service (this isn=E2=80=99t just your normal DataSource), then to build = a filter which selects that. One option for this is to use the = enlistment whiteboard from Aries (not well documented) https://github.com/apache/aries/tree/trunk/transaction/transact= ion-jdbc

This is a non-trivial thing to do, which is why I keep = mentioning Transaction Control which handles the enlistment reliably = without the layers of services. 

Best Regards,

Tim

Sent from my iPhone

On 16 May 2018, at 21:57, Alex Soto <alex.soto@envieta.com> wrote:

Thank you Tim.

Any idea what the JNDI names would = be?
It is Pax-JDBC creating these JNDI names, so I have = no idea.

=46rom = the Karaf console:


karaf@root()> jndi:names 
JNDI = Name              =E2=94=82 = Class Name
=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80= =E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2= =94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94= =BC=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80= =E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2= =94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94= =80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80= =E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2= =94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80
osgi:service/responder =E2=94=82 = org.mariadb.jdbc.MySQLDataSource
osgi:service/jndi  =     =E2=94=82 = org.apache.karaf.jndi.internal.JndiServiceImpl


Best = regards,
Alex soto




On May 16, 2018, at 3:48 PM, Tim Ward <tim.ward@paremus.com> wrote:

Just = looking quickly.

You have the same JNDI = name for both JTA and non JTA DataSources. This is clearly wrong as the = DataSource cannot simultaneously be enlisted in the Transaction and not = enlisted. The comments also indicate a misunderstanding of the purpose = of the non-jta-datasource, which absolutely is used with JTA = EntityManagers (for things like sequence allocation and out of band = optimisations). You really do need to have both and they do need to = behave differently.

At a guess your = DataSource is not enlisted with the transaction manager present in the = system.  This usually happens by configuring a (otherwise = invisible) DataSource wrapper There is nothing forcing you to make this = happen (or checking that it does) hence your transactions would be = broken. This is one of the several reasons I try to direct people to = Transaction Control where the model actively pushes you toward = transactions that actually work, rather than hiding all the magic behind = an annotation.

Hopefully this gives you = some clues as to what might be wrong.

Best = Regards,

Tim

Sent from my iPhone

On 16 May 2018, at 21:34, Jean-Baptiste Onofr=C3=A9= <jb@nanthrax.net>= wrote:

Are you sure about your code ? = Flush looks weird to me and it seems you don't use container managed = transaction.

Regards
JB

On = 16/05/2018 21:08, Alex Soto wrote:
Yes, same result. =  I even tried with Narayana Transaction Manager, and same = result.
Best regards,
Alex soto
On May 16, 2018, at 2:56 = PM, Jean-Baptiste Onofr=C3=A9 <jb@nanthrax.net <mailto:jb@nanthrax.net>> wrote:

Same behavior with RequiresNew ?

Regards
JB

On 16/05/2018 19:44, = Alex Soto wrote:
With Karaf version 4.2.0, Rollback is not = working with MariaDB and InnoDB tables.
I deployed these = features (from Karaf=E2=80=99s enterprise  repository):
<feature>aries-blueprint</feature>
<feature>transaction</feature>
<feature>jndi</feature>
<feature>jdbc</feature>
<feature>jpa</feature>
<feature>pax-jdbc-mariadb</feature>
=        <feature>pax-jdbc-config&l= t;/feature>
<feature>pax-jdbc-pool-dbcp2</feature>
<feature>hibernate</feature>
My = Data Source is configured in the file = /org.ops4j.datasource-responder.cfg/
=   osgi.jdbc.driver.name =3D mariadb
=   dataSourceName=3Dresponder
  url
  =3D jdbc:mariadb://mariadb.local:3306/responder?characterEncoding=3DUTF-= 8&useServerPrepStmts=3Dtrue&autocommit=3Dfalse
=   user=3DXXXX
  password=3DXXXX
  databaseName=3Dresponder
=   #Pool Config
  pool=3Ddbcp2
  xa=3Dtrue
My persistence.xml:
  <persistence version=3D"2.0" xmlns=3D"http://java.sun.com/xml/ns/persistence"
=        xmlns:xsi=3D"http://www.w3.org/2001/XMLSchema-instance"
=        xsi:schemaLocation=3D"http://java.sun.com/xml/ns/persistence
http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"= >
=            <pers= istence-unit name=3D"responderPersistenUnit" = transaction-type=3D"JTA">
=             &n= bsp;  <provider>org.hibernate.jpa.HibernatePersistenceProv= ider</provider>
=            <!-- = Only used when transaction-type=3DJTA -->
=             &n= bsp;  <jta-data-source>osgi:service/javax.sql.DataSource/(= osgi.jndi.service.name=3Dresponder)</jta-data-source>
= =            <!-- = Only used when transaction-type=3DRESOURCE_LOCAL -->
=             &n= bsp;  <non-jta-data-source>osgi:service/javax.sql.DataSour= ce/(osgi.jndi.service.name=3Dresponder)</non-jta-data-source>
=            <prop= erties>
=             &n= bsp;      <property = name=3D=E2=80=9Chibernate.dialect" = value=3D"org.hibernate.dialect.MySQL5Dialect" />
=             &n= bsp;  <property name=3D"hibernate.show_sql" value=3D"true" = />
=             &n= bsp;  <property name=3D"hibernate.format_sql" value=3D"true" = />
=             &n= bsp;  <property name=3D"hibernate.hbm2ddl.auto" = value=3D"none"/>
=            </pro= perties>
=        </persistence-unit>
  </persistence>
My = blueprint.xml:
  <blueprint xmlns=3D"http://www.osgi.org/xmlns/blueprint/v1.0.0"
=   xmlns:jpa=3D"http://aries.apache.org/xmlns/jpa/v2.0.0"
=   xmlns:tx=3D"http://aries.apache.org/xmlns/transactions/v2.0.0"
  xmlns:xsi=3D"http://www.w3.org/2001/XMLSchema-instance"
=   xsi:schemaLocation=3D"http://www.osgi.org/xmlns/blueprint/v1.0.0
https://osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd"><= br class=3D"">   <jpa:enable />
=   <tx:enable />
  <bean = id=3D"userService" class=3D"org.data.impl.UserServiceImpl" />
  <service ref=3D"userService" = interface=3D"org.data.UserService" />
=   </blueprint>
For testing I throw = exception in my DAO:
@Transactional(REQUIRED)
public void addUser(User user) {
em.persist(user);
em.flush();
throw= new RuntimeException("On Purpose");
}
I = expect the record not to be in the table due to rollback of the = transaction, but it still shows up in my database table.
Best regards,
Alex soto

<= /div>

<= /div>
<= /div>
<= br class=3D"">= --Apple-Mail=_13D25162-4109-4D05-9544-BC1EE46E63BD--