Ok, I made some progress (I guess) I am no longer getting the original error: java.lang.ClassCastException: org.apache.openjpa.persistence.PersistenceProviderImpl cannot be cast to javax.persistence.spi.PersistenceProvider
I added my own version of the jpa feature, in which I substitute the line <bundle dependency="true">mvn:org.eclipse.persistence/javax.persistence/2.1.0</bundle> With: <bundle dependency="true">mvn:org.apache.geronimo.specs/geronimo-jta_1.1_spec/1.1.1</bundle> Which results in: <feature name="aries-jpa2”> <capability> osgi.service;effective:=active;objectClass=javax.persistence.spi.PersistenceProvider </capability> <bundle dependency="true">mvn:org.apache.geronimo.specs/geronimo-jpa_2.0_spec/1.1</bundle> <bundle dependency="true">mvn:org.apache.geronimo.specs/geronimo-jta_1.1_spec/1.1.1</bundle> <bundle dependency="true">mvn:org.osgi/org.osgi.service.jdbc/1.0.0</bundle> <bundle dependency="true" start-level="30">mvn:org.apache.felix/org.apache.felix.coordinator/1.0.2</bundle> <bundle start-level="30">mvn:org.apache.aries.jpa/org.apache.aries.jpa.api/${aries.jpa.version}</bundle> <bundle start-level="30">mvn:org.apache.aries.jpa/org.apache.aries.jpa.container/${aries.jpa.version}</bundle> <bundle start-level="30">mvn:org.apache.aries.jpa/org.apache.aries.jpa.support/${aries.jpa.version}</bundle> <conditional> <condition>aries-blueprint</condition> <bundle start-level="30">mvn:org.apache.aries.jpa/org.apache.aries.jpa.blueprint/${aries.jpa.version}</bundle> </conditional> </feature> Now, in my own feature, I have: <feature>aries-blueprint</feature> <feature>jndi</feature> <feature>jdbc</feature> <feature>transaction</feature> <feature>aries-jpa2</feature> <feature>openjpa</feature> <feature>pax-jdbc-mariadb</feature> <feature>pax-jdbc-config</feature> Among others. Now my bundle fails to start: Status: GracePeriod Declarative Services Blueprint 5/11/18 2:14 PM Missing dependencies: (&(osgi.unit.name=responderPersistenUnit)(objectClass=javax.persistence.EntityManager)) There are no errors in the log, just this unresolved dependency. Any idea about why my persistent unit is not being registered? Best regards, Alex soto > On May 11, 2018, at 11:09 AM, Tim Ward <tim.w...@paremus.com> wrote: > > > >> On 11 May 2018, at 15:53, Alex Soto <alex.s...@envieta.com >> <mailto:alex.s...@envieta.com>> wrote: >> >> Thanks for the help Tim. >> >>> On May 11, 2018, at 10:24 AM, Tim Ward <tim.w...@paremus.com >>> <mailto:tim.w...@paremus.com>> wrote: >>> >>> Aries JPA can work with either JPA 2.0, or JPA 2.1, and is tested with >>> EclipseLink, Hibernate and OpenJPA. >> >> I am looking at these integration tests, but the test itself does not uses >> the feature, as defined in the feature.xml file. It loads a different >> version of javax.persistence for the OpenJPA integration test. So unless you >> are an AriesJPA developer, you would not know about this. How would anybody >> figure this out? >> >> @Configuration >> public Option[] configuration() { >> return new Option[] { >> baseOptions(), // >> ariesJpa20(), // >> jta11Bundles(), // Openjpa currently does not work with jta 1.2. >> See https://issues.apache.org/jira/browse/OPENJPA-2607 >> <https://issues.apache.org/jira/browse/OPENJPA-2607> >> openJpa(), // >> derbyDSF(), // >> testBundle() >> }; >> >> Then the example does not use OpenJPA, but Hibernate, so there is no >> information on how to make it work with OpenJPA out of the box. >> One option here would be to have multiple specific features: jpa-hibernate, >> jpa-openjpa, etc. > > Yes, that’s pretty much what is needed, but Karaf would be the place to > create and maintain those features. > >> >>> >>> It is highly recommended that you use the JavaJPA contract in any of your >>> bundles using JPA so that you are isolated from the API version number >>> changes in the future (most Java EE specifications make major version bumps >>> quite regularly). >>> >> >> I have this in my bundle’s osgi.bnd file: >> >> -contract: JavaJPA >> >> Is that all that is needed? It does not indicate version. > > That is most of what is needed - you also need to be compiling against a > library which offers the contract (for example the spec bundles provided by > Aries). If you do that you will end up with Import-Package statements for > javax.persistence (et al) with no version, but also a Require-Capability: > osgi.contract;filter:=(&(osgi.contract=JavaJPA)(version=XXX)) where the XXX > is determined from the Provide-Capability of the bundle you compiled against. > >> >>> The real problem is that the AriesJPA feature shouldn’t exist as a >>> standalone thing (it doesn’t make sense to deploy it on its own). It should >>> come for free when you install the OpenJPA (or Hibernate, or EclipseLink) >>> feature, using whichever API they have deployed. >> >> Exactly, this is harder than it should be. When I install a feature, I >> expect the feature to bring in all that is needed, not having to chase down >> all these dependencies. >> Is there an intention to take this approach any time soon? > > I’m afraid that would be a decision for the Karaf maintainers rather than me. > I’m only chipping in because I’m an Aries PMC member who deals quite a bit > with the JPA and Tx Control components. > > Best Regards, > > Tim Ward > >> >> >> >> >>> >>> Tim >>> >>> >>>> On 11 May 2018, at 14:23, Alex Soto <alex.s...@envieta.com >>>> <mailto:alex.s...@envieta.com>> wrote: >>>> >>>> I had accidentally replied directly to Tim. Repeating here: >>>> >>>> Let me see if I understand this correctly: >>>> >>>> Karaf version 4.2.0 enterprise repository depends on version 2.6.1 of >>>> AriesJPA. >>>> AriesJPA version 2.6.1 depends on javax.persistence version 2.1.0. >>>> Karaf’s enterprise repository defines a openjpa feature that depends on >>>> OpenJPA version 2.4.2. >>>> OpenJPA version 2.4.2 depends on javax.persistence version 2.0.0. >>>> >>>> Is this correct? >>>> Is there is a bug in the Enterprise repository mixing incompatible >>>> versions of OpenJPA and AriesJPA? >>>> Is the problem in OpenJPA not declaring the version it depends on? >>>> >>>> Inspecting in Karaf’s console: >>>> >>>> karaf@root()> list >>>> >>>> 97 │ Active │ 80 │ 2.4.2 │ OpenJPA Aggregate Ja >>>> >>>> karaf@root()> bundle:requirements 97 >>>> >>>> osgi.wiring.package; >>>> (&(osgi.wiring.package=javax.persistence)(version>=1.1.0)(!(version>=2.1.0))) >>>> resolved by: >>>> osgi.wiring.package; javax.persistence 2.0.0 from >>>> org.apache.geronimo.specs.geronimo-jpa_2.0_spec [66] >>>> >>>> >>>> karaf@root()> feature:info jpa >>>> Feature jpa 2.6.1 >>>> Description: >>>> OSGi Persistence Container >>>> Details: >>>> JPA implementation provided by Apache Aries JPA 2.x. NB: this feature >>>> doesn't provide the JPA engine, you have to install one by yourself >>>> (OpenJPA for instance) >>>> Feature has no configuration >>>> Feature has no configuration files >>>> Feature has no dependencies. >>>> Feature contains followed bundles: >>>> mvn:org.eclipse.persistence/javax.persistence/2.1.0 >>>> mvn:org.apache.geronimo.specs/geronimo-jta_1.1_spec/1.1.1 >>>> mvn:org.osgi/org.osgi.service.jdbc/1.0.0 >>>> mvn:org.apache.felix/org.apache.felix.coordinator/1.0.2 start-level=30 >>>> mvn:org.apache.aries.jpa/org.apache.aries.jpa.api/2.6.1 start-level=30 >>>> mvn:org.apache.aries.jpa/org.apache.aries.jpa.container/2.6.1 >>>> start-level=30 >>>> mvn:org.apache.aries.jpa/org.apache.aries.jpa.support/2.6.1 >>>> start-level=30 >>>> >>>> Best regards, >>>> Alex soto >>>> >>>> >>>> >>>> >>>>> On May 10, 2018, at 5:45 PM, Tim Ward <tim.w...@paremus.com >>>>> <mailto:tim.w...@paremus.com>> wrote: >>>>> >>>>> OpenJPA 2.4.x supports JPA 2.0 (not 2.1) you can get the API you need >>>>> from Apache Aries, as well as the JPA container. This is also all used >>>>> and tested with Aries Transaction Control, so you can look at the bundles >>>>> used there. >>>>> >>>>> Best Regards, >>>>> >>>>> Tim >>>>> >>>>> Sent from my iPhone >>>>> >>>>>> On 10 May 2018, at 20:43, Jean-Baptiste Onofré <j...@nanthrax.net >>>>>> <mailto:j...@nanthrax.net>> wrote: >>>>>> >>>>>> Anyway, let me check if OpenJPA 2.4.2 supports JPA 2.1 (it's what I >>>>>> thought). >>>>>> >>>>>> Regards >>>>>> JB >>>>>> >>>>>>> On 05/10/2018 09:36 PM, Alex Soto wrote: >>>>>>> I am sorry I only see one version: >>>>>>> >>>>>>> karaf@root()> feature:list | grep jpa >>>>>>> openjpa │ 2.4.2 │ │ >>>>>>> Started │ enterprise-4.2.0 │ Apache OpenJPA 2.4.x >>>>>>> persistence engine support >>>>>>> camel-jpa │ 2.21.1 │ >>>>>>> │ Uninstalled │ camel-2.21.1 │ >>>>>>> deltaspike-jpa │ 1.4.2 │ >>>>>>> │ Uninstalled │ org.ops4j.pax.cdi-1.0.0.RC2 │ Apache Deltaspike >>>>>>> jpa support >>>>>>> deltaspike-jpa │ 1.8.1 │ >>>>>>> │ Uninstalled │ org.ops4j.pax.cdi-1.0.0 │ Apache Deltaspike >>>>>>> jpa support >>>>>>> jpa │ 2.6.1 │ │ >>>>>>> Started │ aries-jpa-2.6.1 │ OSGi Persistence >>>>>>> Container >>>>>>> >>>>>>> >>>>>>> >>>>>>> Is there a repository I need to add? >>>>>>> >>>>>>> Best regards, >>>>>>> Alex soto >>>>>>> >>>>>>> >>>>>>> >>>>>>>> On May 10, 2018, at 3:25 PM, Jean-Baptiste Onofré <j...@nanthrax.net >>>>>>>> <mailto:j...@nanthrax.net> >>>>>>>> <mailto:j...@nanthrax.net <mailto:j...@nanthrax.net>>> wrote: >>>>>>>> >>>>>>>> Karaf provides both jpa 1.x and 2.x feature. >>>>>>>> >>>>>>>> You just have to install the right one depending of the engine you >>>>>>>> are using: >>>>>>>> >>>>>>>> feature:install jpa/1.x >>>>>>>> feature:install openjpa >>>>>>>> >>>>>>>> Regards >>>>>>>> JB >>>>>>>> >>>>>>>>> On 05/10/2018 09:23 PM, Alex Soto wrote: >>>>>>>>> Thanks JB, >>>>>>>>> >>>>>>>>> I was hoping to use whatever was defined in the Karaf’s enterprise >>>>>>>>> feature, >>>>>>>>> but if that doesn’t work ,then which version do I need? I am afraid >>>>>>>>> if I >>>>>>>>> deviate from the versions selected by Kara’s Enterprise feature I >>>>>>>>> will get >>>>>>>>> into more version mismatch problems. Also what do I put in my POM >>>>>>>>> for >>>>>>>>> javax.persistence dependency? >>>>>>>>> >>>>>>>>> >>>>>>>>> Best regards, >>>>>>>>> Alex soto >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>>> On May 10, 2018, at 3:16 PM, Jean-Baptiste Onofré <j...@nanthrax.net >>>>>>>>>> <mailto:j...@nanthrax.net> >>>>>>>>>> <mailto:j...@nanthrax.net <mailto:j...@nanthrax.net>>> wrote: >>>>>>>>>> >>>>>>>>>> Hi, >>>>>>>>>> >>>>>>>>>> OpenJPA 2.x still uses JPA 1.x. By default, jpa feature will provide >>>>>>>>>> 2.x >>>>>>>>>> version. >>>>>>>>>> >>>>>>>>>> You should specify the jpa feature version. >>>>>>>>>> >>>>>>>>>> Regards >>>>>>>>>> JB >>>>>>>>>> >>>>>>>>>>> On 05/10/2018 09:08 PM, Alex Soto wrote: >>>>>>>>>>> Hello, >>>>>>>>>>> >>>>>>>>>>> I am running Karaf 4.2.0, trying to setup a project with OpenJPA. >>>>>>>>>>> I am getting >>>>>>>>>>> error: >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> 14:44:07.799 ERROR [FelixDispatchQueue] FrameworkEvent ERROR >>>>>>>>>>> - org.apache.aries.jpa.container >>>>>>>>>>> java.lang.ClassCastException: >>>>>>>>>>> org.apache.openjpa.persistence.PersistenceProviderImpl >>>>>>>>>>> cannot be cast to javax.persistence.spi.PersistenceProvider >>>>>>>>>>> at >>>>>>>>>>> org.apache.aries.jpa.container.impl.PersistenceProviderTracker.addingService(PersistenceProviderTracker.java:84) >>>>>>>>>>> ~[?:?] >>>>>>>>>>> at >>>>>>>>>>> org.apache.aries.jpa.container.impl.PersistenceProviderTracker.addingService(PersistenceProviderTracker.java:44) >>>>>>>>>>> ~[?:?] >>>>>>>>>>> at >>>>>>>>>>> org.osgi.util.tracker.ServiceTracker$Tracked.customizerAdding(ServiceTracker.java:941) >>>>>>>>>>> ~[?:?] >>>>>>>>>>> at >>>>>>>>>>> org.osgi.util.tracker.ServiceTracker$Tracked.customizerAdding(ServiceTracker.java:870) >>>>>>>>>>> ~[?:?] >>>>>>>>>>> at >>>>>>>>>>> org.osgi.util.tracker.AbstractTracked.trackAdding(AbstractTracked.java:256) >>>>>>>>>>> ~[?:?] >>>>>>>>>>> at >>>>>>>>>>> org.osgi.util.tracker.AbstractTracked.trackInitial(AbstractTracked.java:183) >>>>>>>>>>> ~[?:?] >>>>>>>>>>> at >>>>>>>>>>> org.osgi.util.tracker.ServiceTracker.open(ServiceTracker.java:318) >>>>>>>>>>> ~[?:?] >>>>>>>>>>> at >>>>>>>>>>> org.osgi.util.tracker.ServiceTracker.open(ServiceTracker.java:261) >>>>>>>>>>> ~[?:?] >>>>>>>>>>> at >>>>>>>>>>> org.apache.aries.jpa.container.impl.PersistenceBundleTracker.trackProvider(PersistenceBundleTracker.java:103) >>>>>>>>>>> ~[?:?] >>>>>>>>>>> at >>>>>>>>>>> org.apache.aries.jpa.container.impl.PersistenceBundleTracker.findPersistenceUnits(PersistenceBundleTracker.java:87) >>>>>>>>>>> ~[?:?] >>>>>>>>>>> at >>>>>>>>>>> org.apache.aries.jpa.container.impl.PersistenceBundleTracker.addingBundle(PersistenceBundleTracker.java:66) >>>>>>>>>>> ~[?:?] >>>>>>>>>>> at >>>>>>>>>>> org.apache.aries.jpa.container.impl.PersistenceBundleTracker.addingBundle(PersistenceBundleTracker.java:39) >>>>>>>>>>> ~[?:?] >>>>>>>>>>> at >>>>>>>>>>> org.osgi.util.tracker.BundleTracker$Tracked.customizerAdding(BundleTracker.java:469) >>>>>>>>>>> ~[?:?] >>>>>>>>>>> at >>>>>>>>>>> org.osgi.util.tracker.BundleTracker$Tracked.customizerAdding(BundleTracker.java:415) >>>>>>>>>>> ~[?:?] >>>>>>>>>>> at >>>>>>>>>>> org.osgi.util.tracker.AbstractTracked.trackAdding(AbstractTracked.java:256) >>>>>>>>>>> ~[?:?] >>>>>>>>>>> at >>>>>>>>>>> org.osgi.util.tracker.AbstractTracked.track(AbstractTracked.java:229) >>>>>>>>>>> ~[?:?] >>>>>>>>>>> at >>>>>>>>>>> org.osgi.util.tracker.BundleTracker$Tracked.bundleChanged(BundleTracker.java:444) >>>>>>>>>>> ~[?:?] >>>>>>>>>>> at >>>>>>>>>>> org.apache.felix.framework.EventDispatcher.invokeBundleListenerCallback(EventDispatcher.java:915) >>>>>>>>>>> ~[?:?] >>>>>>>>>>> at >>>>>>>>>>> org.apache.felix.framework.EventDispatcher.fireEventImmediately(EventDispatcher.java:834) >>>>>>>>>>> ~[?:?] >>>>>>>>>>> at >>>>>>>>>>> org.apache.felix.framework.EventDispatcher.fireBundleEvent(EventDispatcher.java:516) >>>>>>>>>>> ~[?:?] >>>>>>>>>>> at >>>>>>>>>>> org.apache.felix.framework.Felix.fireBundleEvent(Felix.java:4579) >>>>>>>>>>> ~[?:?] >>>>>>>>>>> at org.apache.felix.framework.Felix.startBundle(Felix.java:2174) >>>>>>>>>>> ~[?:?] >>>>>>>>>>> at >>>>>>>>>>> org.apache.felix.framework.Felix.setActiveStartLevel(Felix.java:1373) >>>>>>>>>>> ~[?:?] >>>>>>>>>>> at >>>>>>>>>>> org.apache.felix.framework.FrameworkStartLevelImpl.run(FrameworkStartLevelImpl.java:308) >>>>>>>>>>> ~[?:?] >>>>>>>>>>> at java.lang.Thread.run(Thread.java:748) [?:?] >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> This looks like version mismatch. I am loading the following >>>>>>>>>>> packages in my >>>>>>>>>>> feature: >>>>>>>>>>> >>>>>>>>>>> <feature>aries-blueprint</feature> >>>>>>>>>>> <feature>war</feature> >>>>>>>>>>> <feature>camel-core</feature> >>>>>>>>>>> <feature>camel-servlet</feature> >>>>>>>>>>> <feature>camel-blueprint</feature> >>>>>>>>>>> <feature>camel-jackson</feature> >>>>>>>>>>> <feature>jndi</feature> >>>>>>>>>>> <feature>jdbc</feature> >>>>>>>>>>> <feature>transaction</feature> >>>>>>>>>>> <feature>jpa</feature> >>>>>>>>>>> <feature>openjpa</feature> >>>>>>>>>>> <feature>pax-jdbc-mariadb</feature> >>>>>>>>>>> <feature>pax-jdbc-config</feature> >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> One thing I don’t know if is correct is the javax.persistence >>>>>>>>>>> dependency in >>>>>>>>>>> my POM: >>>>>>>>>>> >>>>>>>>>>> <dependency> >>>>>>>>>>> <groupId>org.eclipse.persistence</groupId> >>>>>>>>>>> <artifactId>javax.persistence</artifactId> >>>>>>>>>>> <version>2.0.5</version> >>>>>>>>>>> <scope>provided</scope> >>>>>>>>>>> </dependency> >>>>>>>>>>> >>>>>>>>>>> Any hints? >>>>>>>>>>> >>>>>>>>>>> Best regards, >>>>>>>>>>> Alex soto >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>> >>>>>>>>>> -- >>>>>>>>>> Jean-Baptiste Onofré >>>>>>>>>> jbono...@apache.org <mailto:jbono...@apache.org> >>>>>>>>>> <mailto:jbono...@apache.org <mailto:jbono...@apache.org>> >>>>>>>>>> http://blog.nanthrax.net <http://blog.nanthrax.net/> >>>>>>>>>> Talend - http://www.talend.com <http://www.talend.com/> >>>>>>>>> >>>>>>>> >>>>>>>> -- >>>>>>>> Jean-Baptiste Onofré >>>>>>>> jbono...@apache.org <mailto:jbono...@apache.org> >>>>>>>> <mailto:jbono...@apache.org <mailto:jbono...@apache.org>> >>>>>>>> http://blog.nanthrax.net <http://blog.nanthrax.net/> >>>>>>>> Talend - http://www.talend.com <http://www.talend.com/> >>>>>>> >>>>>> >>>>>> -- >>>>>> Jean-Baptiste Onofré >>>>>> jbono...@apache.org <mailto:jbono...@apache.org> >>>>>> http://blog.nanthrax.net <http://blog.nanthrax.net/> >>>>>> Talend - http://www.talend.com <http://www.talend.com/>