2

I need some help with troubleshooting why my persistence unit is not loaded in Karaf using Hibernate. The log file reports

Bundle com.vogelware.simple.remote.combined is waiting for dependencies [(&(&(org.apache.aries.jpa.proxy.factory=true)(osgi.unit.name=person)(objectClass=javax.persistence.EntityManagerFactory))].

I think the issue is the EntityManagerFactory service is not running. Based on SO message Jpa-hibernate error while starting the service all of the required services are running. See below.

I have tried starting my persistence bundle before hibernate bundles but get the same behavior.

Listed below are the blueprints for datasource, persistence and persistence.xml.

Any suggestions on how to get this simple example running?

Features and bundles with version installed

karaf@root> feature:list -i
Name        | Version          | Installed | Repository              | Description
-------------------------------------------------------------------------------------------------------------------------
standard    | 3.0.1            | x         | standard-3.0.1          | Karaf standard feature
config      | 3.0.1            | x         | standard-3.0.1          | Provide OSGi ConfigAdmin support
region      | 3.0.1            | x         | standard-3.0.1          | Provide Region Support
package     | 3.0.1            | x         | standard-3.0.1          | Package commands and mbeans
http        | 3.0.1            | x         | standard-3.0.1          | Implementation of the OSGI HTTP Service
kar         | 3.0.1            | x         | standard-3.0.1          | Provide KAR (KARaf archive) support
ssh         | 3.0.1            | x         | standard-3.0.1          | Provide a SSHd server on Karaf
management  | 3.0.1            | x         | standard-3.0.1          | Provide a JMX MBeanServer and a set of MBeans in K
transaction | 1.0.1            | x         | enterprise-3.0.1        | OSGi Transaction Manager
jpa         | 1.0.1            | x         | enterprise-3.0.1        | OSGi Persistence Container
hibernate   | 4.3.1.Final      | x         | enterprise-3.0.1        | Hibernate 4.3.x JPA persistence engine support
jndi        | 3.0.1            | x         | enterprise-3.0.1        | OSGi Service Registry JNDI access
pax-jetty   | 8.1.14.v20131031 | x         | org.ops4j.pax.web-3.1.0 | Provide Jetty engine support
pax-http    | 3.1.0            | x         | org.ops4j.pax.web-3.1.0 | Implementation of the OSGI HTTP Service

karaf@root> bundle:list
START LEVEL 100 , List Threshold: 50
 ID | State       | Lvl | Version               | Name
---------------------------------------------------------------------------------------
 86 | Active      |  80 | 3.0.1                 | Apache Karaf :: JNDI :: Command
114 | Active      |  80 | 2.7.7.5               | Apache ServiceMix :: Bundles :: antlr
115 | Active      |  80 | 1.8.2.2               | Apache ServiceMix :: Bundles :: ant
116 | Active      |  80 | 1.6.1.5               | Apache ServiceMix :: Bundles :: dom4j
117 | Active      |  80 | 1.14.1.1              | Apache ServiceMix :: Bundles :: serp
118 | Active      |  80 | 0.9.0                 | ClassMate
119 | Active      |  80 | 3.18.1.GA             | Javassist
120 | Active      |  80 | 1.0.2.Final           | JACC 1.4 API
121 | Active      |  80 | 0                     | wrap_mvn_org.jboss_jandex_1.1.0.Final
122 | Active      |  80 | 3.1.4.GA              | JBoss Logging 3
123 | Active      |  80 | 4.0.4.Final           | hibernate-commons-annotations
124 | Active      | 100 | 4.3.1.Final           | hibernate-core
125 | Active      | 100 | 4.3.1.Final           | hibernate-entitymanager
126 | Active      | 100 | 4.3.1.Final           | hibernate-osgi
127 | Active      |  80 | 10.10.1000001.1458268 | Apache Derby 10.10
128 | Active      |  80 | 0.0.0                 | derby-datasource.xml
129 | GracePeriod |  80 | 0.1.0.201411290933    | Remote with JPA
130 | Active      |  80 | 0.1.0.201411280737    | Simple Model API

Running services for EntityManager

karaf@root(service)> list javax.transaction.TransactionManager
[org.apache.aries.transaction.AriesTransactionManager, javax.transaction.TransactionManager, javax.transaction.TransactionSynchroniz
ationRegistry, javax.transaction.UserTransaction, org.apache.geronimo.transaction.manager.RecoverableTransactionManager]
------------------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------
 service.id = 662
Provided by :
 Apache Aries Transaction Manager (93)
Used by:
 Aries JPA Container Managed Contexts (91)

karaf@root(service)> list DataSource
[javax.sql.DataSource]
----------------------
 osgi.jndi.service.name = jdbc/MotorDB
 osgi.service.blueprint.compname = MotorDB
 service.id = 713
Provided by :
 Bundle 130 (my datasource bundle)

@root(service)> list PersistenceProvider
[javax.persistence.spi.PersistenceProvider]
-------------------------------------------
 javax.persistence.provider = org.hibernate.jpa.HibernatePersistenceProvider
 service.id = 708
Provided by :
 hibernate-osgi (125)

Peristence XML

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

    <persistence-unit name="person" transaction-type="JTA">
        <provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
        <jta-data-source>osgi:service/javax.sql.DataSource/(osgi.jndi.service.name=jdbc/MotorDB)</jta-data-source>
        <class>com.vogelware.simple.model.impl.jpa.Person</class>
        <class>com.vogelware.simple.model.impl.jpa.Address</class>
        <exclude-unlisted-classes>true</exclude-unlisted-classes>

        <properties>
        </properties>
    </persistence-unit>
</persistence> 

Datasource blueprint

<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    default-activation="eager">

    <bean id="MotorDB" class="org.apache.derby.jdbc.EmbeddedDataSource">
        <property name="databaseName" value="D:\dev\projects\EASA-DB\motordb" />
    </bean>

    <service ref="MotorDB" interface="javax.sql.DataSource">
        <service-properties>
            <entry key="osgi.jndi.service.name" value="jdbc/MotorDB" />
        </service-properties>
    </service>
</blueprint>

Persistence beans

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

    <bean id="personService" class="com.vogelware.simple.remote.jpa.PersonEntityImplJpa">
        <jpa:context unitname="person" property="entityManager" />
        <tx:transaction method="*" value="Required" />
    </bean>

    <service ref="personService"
        interface="com.vogelware.simple.service.IPersonEntity">
        <service-properties>
            <entry key="osgi.jndi.service.name" value="hibernate/con_managed_personService" />
        </service-properties>
    </service>
</blueprint>
Community
  • 1
  • 1
Timothy Vogel
  • 1,363
  • 2
  • 21
  • 39
  • I changed the persistence.xml to have the PersistenceProvider that matches the service org.hibernate.jpa.HibernatePersistenceProvider but still get waiting for dependencies. – Timothy Vogel Nov 29 '14 at 16:17

1 Answers1

2

You are most likely experiencing a bug in aries jpa. Can you try with karaf 3.0.2? It includes the newer aries jpa feature. You also should check that you only have the jpa 2.1 api loaded. If you have jpa 2.0 and 2.1 apis loaded it will not work.

Christian Schneider
  • 19,420
  • 2
  • 39
  • 64
  • Christian ... thanks for helping on the weekend! I tried Karaf 3.02 and also with enterprise feature 3.02-SNAPSHOT. Same results for both attempts. No EntityManagerService started. I'm not sure how to check witch version of JPA is loaded. – Timothy Vogel Nov 29 '14 at 19:34
  • Unfortunately karaf 3.0.2 also does not contain the newest version. We just had a request on the karaf user list like yours. You can try with a custom feature for now . See https://github.com/cschneider/Karaf-Tutorial/blob/master/tasklist-cdi/features/src/main/resources/features.xml There I configure karaf to use hibernate 4.3 and the newest aries releases. With these it works quite well. For the next karaf version we will make sure the standard features already include that. – Christian Schneider Nov 30 '14 at 11:31
  • Thanks again for the tutorial! I found the issue. I was missing the Meta-Persistence: META-INF/persistence.xml header in MANIFEST.MF in my persistence bundle. – Timothy Vogel Dec 05 '14 at 14:47
  • Cool it works now. The maven blueprint plugin that was missing is now also released. – Christian Schneider Dec 05 '14 at 19:57