I'm trying to use Apache Aries JPA in combination with Eclipselink (and an MSSQL database). My OSGi framework is Apache Felix, and I'm using DS (by using BndTools). After a long process of trial and error, I found the necessary bundles:
- javax.persistence
- bundle that contains a DataSourceFactory for jdbc.mssql
- org.apache.aries.jpa.api
- org.apache.aries.jpa.container
- org.apache.aries.jpa.support
- org.apache.aries.transaction.manager
- org.apache.aries.jpa.javax.persistence_2.0
- org.apache.aries.util
- org.apache.geronimo.specs.geronimo-jta_1.1_spec
- org.apache.aries.jpa.eclipselink.adapter
- org.eclipse.persistence.antlr
- org.eclipse.persistence.asm
- org.eclipse.persistence.core
- org.eclipse.persistence.jpa
- org.eclipse.persistence.jpa.jpql
When I start this configuration, I get following Exception:
java.lang.NoClassDefFoundError: javax/sql/DataSource
at org.eclipse.persistence.jpa.PersistenceProvider.createContainerEntityManagerFactoryImpl(PersistenceProvider.java:328)
at org.eclipse.persistence.jpa.PersistenceProvider.createContainerEntityManagerFactory(PersistenceProvider.java:313)
Which bundle should contain the javax.sql.DataSource class? I expected this to be part of the JDK.
Does anyone have an idea by what this is caused or how I can fix this? Of how I can get Apache Aries JPA running with Eclipselink in a DS environment?
Thanks.
Have you looked at the examples/tutorials in the OSGi enRoute project? These walk you through the process of using JPA with OSGi.
It's not clear from the information you have provided how you are trying to make use of Aries JPA, nor what versions of the libraries you are trying to use. The version of Java can also have an impact (Java 9 and 10 removed some entries from the JRE classpath). Depending on what you are doing you probably have too many bundles installed, and they are almost certainly in the wrong place.
Just guessing (based on your statement that you have a bundle that supplies a DataSourceFactory service without saying what that bundle is) you have a wrapped JDBC driver? Has that wrapping been done correctly? If not then that could easily be the source of your NoClassDefFoundError.
As for the bundles, was this the output of a resolve operation? It looks like maybe this has been assembled manually...
- javax.persistence - This is the "official" JPA API, which lacks the JavaJPA contract that you are recommended to use.
- bundle that contains a DataSourceFactory for jdbc.mssql - Unclear where this comes from, but it should be fine as long as you need
- org.apache.aries.jpa.api - Not needed by the Aries JPA container, only needed if you are using the Aries JPA transaction callbacks. If you do want transactions then the OSGi Transaction Control Service (provided by Apache Aries Tx Control)
- org.apache.aries.jpa.container - This is the JPA container, and you definitely need it. Ideally you'll be using Aries JPA 2.7.0, which is the reference implementation of the OSGi R7 JPA Service
- org.apache.aries.jpa.support - Depending on how you're writing your code you may or may not need this. It's the implementation of the API bundle which provides transaction callbacks. Transaction Control is better in pretty much every way.
- org.apache.aries.transaction.manager - Only needed if you're trying to use XA transactions. If you are then you will need more bundles and a lot of DataSource configuration. Again, Aries Transaction Control will do this much more simply, and it's described in the enRoute tutorial.
- org.apache.aries.jpa.javax.persistence_2.0 - Unless you are using a very old EclipseLink then this is very out of date. EclipseLink has been JPA 2.1 for a while, and is now JPA 2.2
- org.apache.aries.util - This won't be needed if you remove some of the other Aries bundles
- org.apache.geronimo.specs.geronimo-jta_1.1_spec - This one is messy. The JTA interface package is split, with only part of it in the JRE. If you are using Java 8 or lower then this bundle needs to be on the classpath and exposed through the system bundle. If you are on Java 9+ then the package has been removed from the JRE, and you can just put the bundle into your framework
- org.apache.aries.jpa.eclipselink.adapter - Needed to register the PersistenceProvider service on behalf of EclipseLink
- org.eclipse.persistence.antlr - Needed by Eclipselink
- org.eclipse.persistence.asm - Needed by Eclipselink
- org.eclipse.persistence.core - This is Eclipselink
- org.eclipse.persistence.jpa - Provides a JPA implementation on top of Eclipselink ORM
- org.eclipse.persistence.jpa.jpql - This provides JPQL query support