Using EclipseLink JPA in OSGI (Karaf)

1.5k Views Asked by At

I am using EclipseLink as my JPA implementation(in KARAF).And following jars are used:-

install -s mvn:org.eclipse.persistence/org.eclipse.persistence.antlr/2.5.0
install -s mvn:org.eclipse.persistence/org.eclipse.persistence.asm/2.5.0
install -s mvn:org.eclipse.persistence/org.eclipse.persistence.core/2.5.0
install -s mvn:org.apache.geronimo.specs/geronimo-jpa_2.0_spec/1.1
install -s mvn:org.osgi/org.osgi.compendium/4.2.0
install -s mvn:org.osgi/org.osgi.enterprise/4.2.0
org.eclipse.gemini.dbaccess.derby_1.0.0.M1-incubation.jar
org.eclipse.gemini.jpa.weaving_1.0.0.RC1.jar
org.eclipse.gemini.jpa_1.0.0.RC1.jar

My persistence.xml is :-

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="1.0"
    xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">

    <persistence-unit name="resource" transaction-type="RESOURCE_LOCAL">
    <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
        <class>myPkg.entity.Resource</class>
        <properties>
            <property name="javax.persistence.jdbc.driver" value="org.apache.derby.jdbc.EmbeddedDriver" 
                /> <property name="javax.persistence.jdbc.url" value="jdbc:derby:DB;create=true" 
                />

            <!-- <property name="javax.persistence.jdbc.driver" value="org.apache.derby.jdbc.ClientDriver" />
            <property name="javax.persistence.jdbc.url" value="jdbc:derby://localhost:1527/D:\DB;create=true" /> -->


            <property name="javax.persistence.jdbc.user" value="test" />
            <property name="javax.persistence.jdbc.password" value="test" />
            <property name="eclipselink.logging.level" value="OFF" />

            <!-- EclipseLink should create the database schema automatically -->
            <property name="eclipselink.ddl-generation" value="create-tables" />
            <property name="eclipselink.ddl-generation.output-mode"
                value="database" />
            <property name="connection.autocommit" value="false" />
            <property name="eclipselink.persistence-context.flush-mode" value="commit" /> 
            <!-- <property name="eclipselink.allow-zero-id" value="true"/> -->
        </properties>
    </persistence-unit>
</persistence>

But the gemini.dbaccess.derby_1.0.0.M1-incubation jar remians in Installed state as well as the gemini.jpa.weaving jar remains in resolved state.

Restarting the gemini.dbaccess.derby_1.0.0.M1-incubation gives the following error:-

Reason: Missing Constraint: Import-Package: org.apache.derby.client.am; version="0.0.0"

And my application gives the following error:-

Could not find data source factory in registry: org.apache.derby.jdbc.ClientDriver

I am new to using eclipseLink in OSGI ,what am i missing here ?

3

There are 3 best solutions below

2
On BEST ANSWER

Apache karaf 4.0.0 has been released,this version of karaf provides eclipseLink support.

feature:install eclipselink

Therefore there is no need to use external adapters for using eclipseLink

3
On

Here is the content of the manifest of org.eclipse.gemini.dbaccess.derby_1.0.0.M1-incubation.jar:

Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Gemini DBAccess (Incubation)
Bundle-SymbolicName: org.eclipse.gemini.dbaccess.derby
Bundle-Version: 1.0.0.M1-incubation
Bundle-Activator: org.eclipse.gemini.dbaccess.derby.Activator
Bundle-Vendor: Oracle Corporation
Bundle-RequiredExecutionEnvironment: J2SE-1.5
Import-Package: javax.sql,
org.apache.derby.client.am,
org.apache.derby.jdbc,
org.osgi.framework;version="[1.3,2)",
org.osgi.service.jdbc;version="[1.0,2.0)"

There are still two unresolved dependencies on Derby binaries:

  • org.apache.derby.client.am
  • org.apache.derby.jdbc

Both lack a version number, this is why the message states 0.0.0.

The two packages are part of the derbyclient.jar file available as an OSGi bundle in the Derby binaries. The problem is that the Export-Package clause of this bundle only exposes the org.apache.derby.jdbc package.

A simple solution is the SpringSource-packaged bundle: it exposes the two required packages. Beware, it has an additional dependency on the Java transaction API.

0
On

First of all, make sure you have the regions feature installed with Karaf, cause if you're using a version < 4 (isn't released yet), the Apache Aries Blueprint implementation is installed by default. So if you want to stick to Gemini, this will interfere. Therefore make sure you have Regions installed. Second I think there is a feature around for installing the eclipse-link bundles. Might want to take a look at it to get the right bundles aligned.

If you would stick to the Aries Blueprint impl, then it's even simpler. Just install the following features:

feature:install jpa jta jndi 

and if you want to use the Derby, might also want to install the jdbc feature. This will give you a bunch of commands to use to connect to a db and/or create a datasource. If you use the datasource commands, you're able to create a datasource for derby database which will install the correct working derby client jars if needed.