Hi Christian, It has nothing to do directly with this issue but I though we should use pax-jdbc-pool-aries instead of pax-jdbc-pool-dbcp2. It's still unclear to me :-). What are the status of these 2 libraries ? What should we use ?
Regards, Arnaud Deprez On Mon, Feb 8, 2016 at 1:01 PM Dutertry Nicolas < [email protected]> wrote: > Thank you Christian ! > > > > -- > > Nicolas Dutertry > > > > *De :* Christian Schneider [mailto:[email protected]] *De la part > de* Christian Schneider > *Envoyé :* lundi 8 février 2016 12:01 > > > *À :* [email protected] > *Objet :* Re: JPA and transaction issue in Karaf 4.0.4 > > > > Hi Nicolas, > > I was able to reproduce the issue and created a jira issue for it > https://issues.apache.org/jira/browse/ARIES-1494 > > I also found the workaround to make the method TestServiceImpl.delete also > @Transactional. Still this is a severe issue and I will try to fix it as > soon as possible. > > Christian > > On 08.02.2016 11:17, Dutertry Nicolas wrote: > > Hi Christian, > > > > Thanks for you answer. I have fixed the 2 issues (correct jpa namespace > and pax-jdbc for datasource) but unfortunately, the error is still there. > > The new code is committed on github. > > Regards, > > -- > > Nicolas > > > > *De :* [email protected] [mailto:[email protected] > <[email protected]>] *De la part de* Christian Schneider > *Envoyé :* samedi 6 février 2016 19:09 > *À :* [email protected] > *Objet :* Re: JPA and transaction issue in Karaf 4.0.4 > > > > Hi Nicolas, > > > > I found some issues with your example but nothing that could fully explain > the error. > > > > 1. In blueprint.xml you use the namespace xmlns:jpa=" > http://aries.apache.org/xmlns/jpan/v1.0.0". This is deprecated. The > correct one is xmlns:jpa="http://aries.apache.org/xmlns/jpa/v2.0.0" > > 2. Your DataSource is not fully JTA enabled. (You are using > org.apache.commons.dbcp2.managed.BasicManagedDataSource) > > > > You can see how to setup dbcp2 in > > > https://github.com/ops4j/org.ops4j.pax.jdbc/blob/master/pax-jdbc-pool-dbcp2/src/main/java/org/ops4j/pax/jdbc/pool/dbcp2/impl/ds/DbcpXAPooledDataSourceFactory.java > > > > I suggest to simply use pax-jdbc-pool-dbcp2 und pax-jdbc-config to create > your DataSource. See > > > https://ops4j1.jira.com/wiki/display/PAXJDBC/Pooling+and+XA+support+for+DataSourceFactory > > > > Can you try if fixing these two issues helps? > > If not then it might be a bug and I will investigate it deeper. > > > > Christian > > > > 2016-02-05 15:07 GMT+01:00 Dutertry Nicolas <[email protected] > >: > > Hi, > > > > I’m trying to migrate an application working with Karaf 3.0.5 to Karaf > 4.0.4. > > I ran into a problem with JPA and transaction management so I have created > a small maven project showing it. > > This sample is available on GitHub : > https://github.com/nicolas-dutertry/test-jpa > > > > The class TestServiceImpl in test-jpa-service has an EntityManager annoted > with @PersistenceContext(unitname = "test") > > The class DeleteManager also has an EntityManager annoted with > @PersistenceContext(unitname = "test") > > > > The method TestServiceImpl.delete is not transactional and it calls the > transactional method DeleteManager.delete several times : > > > > public class TestServiceImpl implements TestService { > > @PersistenceContext(unitName = "test") > > private EntityManager entityManager; > > > > private DeleteManager deleteManager; > > > > … > > > > @Override > > public void delete(String... names) { > > for (String name : names) { > > System.out.println("Deleting " + name); > > deleteManager.delete(name); > > } > > } > > } > > > > public class DeleteManager { > > @PersistenceContext(unitName = "test") > > private EntityManager entityManager; > > > > … > > > > @Transactional > > public void delete(String lastName) { > > Query query = entityManager.createQuery( > > "delete from Person where lastName = :lastName"); > > > > query.setParameter("lastName", lastName); > > query.executeUpdate(); > > } > > } > > > > At runtime it raised a javax.persistence.TransactionRequiredException > during the second call to DeleteManager.delete in the for loop. > > > > To reproduce the problem, compile the sample project with maven: > > > mvn clean install > > > > Then, launch Karaf 4.0.4 and install the kar: > > > kar:install > mvn:com.dutertry.test.karaf.jpa/test-jpa-kar/1.0.0-SNAPSHOT/kar > > > > Then, create new entries in database: > > > person:create Smith 25 > > > person:create Green 23 > > > > Finally delete them: > > > person:delete Smith Green > > > > This will output : > > Deleting Smith > > Deleting Green > > Error executing command: Executing an update/delete query > > > > With the following log : > > 2016-02-05 14:52:32,753 | ERROR | nsole user karaf | > ShellUtil | 44 - org.apache.karaf.shell.core - 4.0.4 > | Exception caught while executing command > > javax.persistence.TransactionRequiredException: Executing an update/delete > query > > at > org.hibernate.jpa.spi.AbstractQueryImpl.executeUpdate(AbstractQueryImpl.java:71) > > at > com.dutertry.test.karaf.jpa.service.impl.DeleteManager.delete(DeleteManager.java:33) > > at sun.reflect.NativeMethodAccessorImpl.invoke0(Native > Method)[:1.7.0_67] > > at > sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)[:1.7.0_67] > > at > sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)[:1.7.0_67] > > at > java.lang.reflect.Method.invoke(Method.java:606)[:1.7.0_67] > > at > org.apache.aries.proxy.impl.ProxyHandler$1.invoke(ProxyHandler.java:54)[21:org.apache.aries.proxy.impl:1.0.4] > > at > org.apache.aries.proxy.impl.ProxyHandler.invoke(ProxyHandler.java:119)[21:org.apache.aries.proxy.impl:1.0.4] > > at > com.dutertry.test.karaf.jpa.service.impl.$DeleteManager1431996488.delete(Unknown > Source)[131:test-jpa-service:1.0.0.SNAPSHOT] > > at > com.dutertry.test.karaf.jpa.service.impl.TestServiceImpl.delete(TestServiceImpl.java:53)[131:test-jpa-service:1.0.0.SNAPSHOT] > > at > Proxy77c92452_69bd_43a7_b242_ba213735af8a.delete(Unknown Source)[:] > > at > com.dutertry.test.karaf.jpa.cmd.DeletePersonCommand.execute(DeletePersonCommand.java:30)[128:test-jpa-cmd:1.0.0.SNAPSHOT] > > at > org.apache.karaf.shell.impl.action.command.ActionCommand.execute(ActionCommand.java:83)[44:org.apache.karaf.shell.core:4.0.4] > > at > org.apache.karaf.shell.impl.console.osgi.secured.SecuredCommand.execute(SecuredCommand.java:67)[44:org.apache.karaf.shell.core:4.0.4] > > at > org.apache.karaf.shell.impl.console.osgi.secured.SecuredCommand.execute(SecuredCommand.java:87)[44:org.apache.karaf.shell.core:4.0.4] > > at > org.apache.felix.gogo.runtime.Closure.executeCmd(Closure.java:480)[44:org.apache.karaf.shell.core:4.0.4] > > at > org.apache.felix.gogo.runtime.Closure.executeStatement(Closure.java:406)[44:org.apache.karaf.shell.core:4.0.4] > > at > org.apache.felix.gogo.runtime.Pipe.run(Pipe.java:108)[44:org.apache.karaf.shell.core:4.0.4] > > at > org.apache.felix.gogo.runtime.Closure.execute(Closure.java:182)[44:org.apache.karaf.shell.core:4.0.4] > > at > org.apache.felix.gogo.runtime.Closure.execute(Closure.java:119)[44:org.apache.karaf.shell.core:4.0.4] > > at > org.apache.felix.gogo.runtime.CommandSessionImpl.execute(CommandSessionImpl.java:94)[44:org.apache.karaf.shell.core:4.0.4] > > at > org.apache.karaf.shell.impl.console.ConsoleSessionImpl.run(ConsoleSessionImpl.java:270)[44:org.apache.karaf.shell.core:4.0.4] > > at java.lang.Thread.run(Thread.java:745)[:1.7.0_67] > > > > Regards, > > -- > > Nicolas Dutertry > > Sopra HR Software - http://www.soprahr.com/ > > > > > > > > -- > > -- > Christian Schneider > http://www.liquid-reality.de > <https://owa.talend.com/owa/redir.aspx?C=3aa4083e0c744ae1ba52bd062c5a7e46&URL=http%3a%2f%2fwww.liquid-reality.de> > > Open Source Architect > http://www.talend.com > <https://owa.talend.com/owa/redir.aspx?C=3aa4083e0c744ae1ba52bd062c5a7e46&URL=http%3a%2f%2fwww.talend.com> > > > > > -- > > Christian Schneider > > http://www.liquid-reality.de > > > > Open Source Architect > > http://www.talend.com > >
