ServiceMix 5.3.0 JPA issue

607 views Asked by At

I have a problem with starting a jpa bundle inside ServiceMix. The problem occurs when using EntityManager injection, while injection of an EntityManagerFactory works fine. Any idea what's wrong?

My persistence.xml:

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.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_2_0.xsd">
    <persistence-unit name="MyUnit" transaction-type="JTA">
        <jta-data-source>osgi:service/javax.sql.DataSource/(osgi.jndi.service.name=jdbc/oracleds)</jta-data-source>

        <class>sandbox.MyEntity</class>

        <properties>
            <property name="openjpa.jdbc.SynchronizeMappings" value="buildSchema"/>
        </properties>

    </persistence-unit>

</persistence>

blueprint.xml:

<?xml version="1.0" encoding="UTF-8"?>
<blueprint
        xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
        xmlns:jpa="http://aries.apache.org/xmlns/jpa/v1.1.0"
        xmlns:tx="http://aries.apache.org/xmlns/transactions/v1.0.0"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd"
>

    <bean id="MyDAO" class="sandbox.dao.impl.MyDAOImpl">
        <tx:transaction method="*" value="Required" />
        <jpa:context property="em" unitname="MyUnit" />
        <!--<jpa:unit property="emf" unitname="MyUnit" />-->
    </bean>

    <service ref="MyDAO" interface="sandbox.dao.MyDAO" />

</blueprint>

Deploying the bundle fails with the following exception:

org.osgi.service.blueprint.container.ComponentDefinitionException: Unable to instantiate components
    at org.apache.aries.blueprint.container.BlueprintContainerImpl.instantiateEagerComponents(BlueprintContainerImpl.java:685)[17:org.apache.aries.blueprint.core:1.4.1]
    at org.apache.aries.blueprint.container.BlueprintContainerImpl.doRun(BlueprintContainerImpl.java:378)[17:org.apache.aries.blueprint.core:1.4.1]
    at org.apache.aries.blueprint.container.BlueprintContainerImpl.run(BlueprintContainerImpl.java:269)[17:org.apache.aries.blueprint.core:1.4.1]
    at org.apache.aries.blueprint.container.BlueprintExtender.createContainer(BlueprintExtender.java:276)[17:org.apache.aries.blueprint.core:1.4.1]
    at org.apache.aries.blueprint.container.BlueprintExtender.createContainer(BlueprintExtender.java:245)[17:org.apache.aries.blueprint.core:1.4.1]
    at org.apache.aries.blueprint.container.BlueprintExtender.modifiedBundle(BlueprintExtender.java:235)[17:org.apache.aries.blueprint.core:1.4.1]
    at org.apache.aries.util.tracker.hook.BundleHookBundleTracker$Tracked.customizerModified(BundleHookBundleTracker.java:500)[12:org.apache.aries.util:1.1.0]
    at org.apache.aries.util.tracker.hook.BundleHookBundleTracker$Tracked.customizerModified(BundleHookBundleTracker.java:433)[12:org.apache.aries.util:1.1.0]
    at org.apache.aries.util.tracker.hook.BundleHookBundleTracker$AbstractTracked.track(BundleHookBundleTracker.java:725)[12:org.apache.aries.util:1.1.0]
    at org.apache.aries.util.tracker.hook.BundleHookBundleTracker$Tracked.bundleChanged(BundleHookBundleTracker.java:463)[12:org.apache.aries.util:1.1.0]
    at org.apache.aries.util.tracker.hook.BundleHookBundleTracker$BundleEventHook.event(BundleHookBundleTracker.java:422)[12:org.apache.aries.util:1.1.0]
    at org.apache.felix.framework.util.SecureAction.invokeBundleEventHook(SecureAction.java:1127)[org.apache.felix.framework-4.4.1.jar:]
    at org.apache.felix.framework.util.EventDispatcher.createWhitelistFromHooks(EventDispatcher.java:696)[org.apache.felix.framework-4.4.1.jar:]
    at org.apache.felix.framework.util.EventDispatcher.fireBundleEvent(EventDispatcher.java:484)[org.apache.felix.framework-4.4.1.jar:]
    at org.apache.felix.framework.Felix.fireBundleEvent(Felix.java:4429)[org.apache.felix.framework-4.4.1.jar:]
    at org.apache.felix.framework.Felix.startBundle(Felix.java:2100)[org.apache.felix.framework-4.4.1.jar:]
    at org.apache.felix.framework.Felix.setActiveStartLevel(Felix.java:1299)[org.apache.felix.framework-4.4.1.jar:]
    at org.apache.felix.framework.FrameworkStartLevelImpl.run(FrameworkStartLevelImpl.java:304)[org.apache.felix.framework-4.4.1.jar:]
    at java.lang.Thread.run(Thread.java:662)[:1.6.0_45]
Caused by: java.lang.NoClassDefFoundError: javax/persistence/criteria/CriteriaUpdate
    at java.lang.Class.getDeclaredMethods0(Native Method)[:1.6.0_45]
    at java.lang.Class.privateGetDeclaredMethods(Class.java:2436)[:1.6.0_45]
    at java.lang.Class.privateGetPublicMethods(Class.java:2556)[:1.6.0_45]
    at java.lang.Class.getMethods(Class.java:1412)[:1.6.0_45]
    at org.apache.aries.blueprint.utils.ReflectionUtils.doGetPublicMethods(ReflectionUtils.java:146)
    at org.apache.aries.blueprint.utils.ReflectionUtils.getPublicMethods(ReflectionUtils.java:130)
    at org.apache.aries.blueprint.utils.ReflectionUtils.getLifecycleMethod(ReflectionUtils.java:114)
    at org.apache.aries.blueprint.container.BeanRecipe.getDestroyMethod(BeanRecipe.java:634)
    at org.apache.aries.blueprint.container.BeanRecipe.internalCreate2(BeanRecipe.java:812)
    at org.apache.aries.blueprint.container.BeanRecipe.internalCreate(BeanRecipe.java:787)
    at org.apache.aries.blueprint.di.AbstractRecipe.create(AbstractRecipe.java:106)[17:org.apache.aries.blueprint.core:1.4.1]
    at org.apache.aries.blueprint.container.BeanRecipe.setProperty(BeanRecipe.java:933)
    at org.apache.aries.blueprint.container.BeanRecipe.setProperties(BeanRecipe.java:907)
    at org.apache.aries.blueprint.container.BeanRecipe.setProperties(BeanRecipe.java:888)
    at org.apache.aries.blueprint.container.BeanRecipe.internalCreate2(BeanRecipe.java:820)
    at org.apache.aries.blueprint.container.BeanRecipe.internalCreate(BeanRecipe.java:787)
    at org.apache.aries.blueprint.di.AbstractRecipe$1.call(AbstractRecipe.java:79)
    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)[:1.6.0_45]
    at java.util.concurrent.FutureTask.run(FutureTask.java:138)[:1.6.0_45]
    at org.apache.aries.blueprint.di.AbstractRecipe.create(AbstractRecipe.java:88)[17:org.apache.aries.blueprint.core:1.4.1]
    at org.apache.aries.blueprint.container.BlueprintRepository.createInstances(BlueprintRepository.java:245)[17:org.apache.aries.blueprint.core:1.4.1]
    at org.apache.aries.blueprint.container.BlueprintRepository.createAll(BlueprintRepository.java:183)[17:org.apache.aries.blueprint.core:1.4.1]
    at org.apache.aries.blueprint.container.BlueprintContainerImpl.instantiateEagerComponents(BlueprintContainerImpl.java:681)[17:org.apache.aries.blueprint.core:1.4.1]
    ... 18 more
Caused by: java.lang.ClassNotFoundException: javax.persistence.criteria.CriteriaUpdate not found by org.apache.geronimo.specs.geronimo-jpa_2.0_spec [202]
    at org.apache.felix.framework.BundleWiringImpl.findClassOrResourceByDelegation(BundleWiringImpl.java:1556)[org.apache.felix.framework-4.4.1.jar:]
    at org.apache.felix.framework.BundleWiringImpl.access$400(BundleWiringImpl.java:77)[org.apache.felix.framework-4.4.1.jar:]
    at org.apache.felix.framework.BundleWiringImpl$BundleClassLoader.loadClass(BundleWiringImpl.java:1993)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:247)[:1.6.0_45]
    at org.apache.felix.framework.BundleWiringImpl.getClassByDelegation(BundleWiringImpl.java:1397)[org.apache.felix.framework-4.4.1.jar:]
    at org.apache.felix.framework.BundleWiringImpl.searchImports(BundleWiringImpl.java:1577)[org.apache.felix.framework-4.4.1.jar:]
    at org.apache.felix.framework.BundleWiringImpl.findClassOrResourceByDelegation(BundleWiringImpl.java:1507)[org.apache.felix.framework-4.4.1.jar:]
    at org.apache.felix.framework.BundleWiringImpl.access$400(BundleWiringImpl.java:77)[org.apache.felix.framework-4.4.1.jar:]
    at org.apache.felix.framework.BundleWiringImpl$BundleClassLoader.loadClass(BundleWiringImpl.java:1993)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:247)[:1.6.0_45]
    ... 41 more

MANIFEST.MF imports:

Import-Package: javax.persistence;version="[1.1,2)",org.osgi.service.blueprint;version="[1.
 0.0,2.0.0)"

Karaf bundles providing javax.persistence package:

karaf@root> packages:exports | grep javax.persistence
   202 javax.persistence; version=1.1.0
   202 javax.persistence.criteria; version=1.1.0
   202 javax.persistence.metamodel; version=1.1.0
   202 javax.persistence.spi; version=1.1.0
   202 javax.persistence; version=2.0.0
   202 javax.persistence.criteria; version=2.0.0
   202 javax.persistence.metamodel; version=2.0.0
   202 javax.persistence.spi; version=2.0.0
karaf@root> osgi:info 202
You are about to access system bundle 202.  Do you wish to continue (yes/no): yes

Apache Geronimo JSR-317 JPA 2.0 Spec API (202)
1

There are 1 answers

2
Peter Keller On BEST ANSWER

Please check your classpath dependencies: javax.persistence.criteria.CriteriaUpdate NoClassDefFoundError was added with JPA 2.1. But according to persistence.xml JPA 2.0 is used in your application.

Edit:

Aries with version >= 1.0.0 depend on JPA 2.1, see its pom.xml file here, and you should update the MANIFEST.MF imports accordingly.