Hi,

I would like to receive some help about a non resolving provider service in
a very simple test bundle I wrote to test TransactionControl with
JPAEntityManagerProvider usage with Hibernate on Karaf 4.2.

The core of the program is a "DAO Service" and both interface and
implementation are reported below.

It seems the bundle hangs waiting for this missing service provider:
    @Reference(target = "(osgi.unit.name=tasklist)")
    void setProvider(JPAEntityManagerProvider provider)

Is anyone so kind to explain me what is missing?

I included the list of features and bundle installed on karaf as well.

I created the datasource this way:
    jdbc:ds-create -dbName reactive -dn mysql -dc com.mysql.jdbc.Driver -u
root -p root -url "jdbc:mysql://localhost:3306/reactive" reactive

Thanks in advance


API-------------------------------------------------------------------

package fake.test.xa.api;

import java.util.Collection;

import javax.jws.WebService;

public interface TaskService {
    Task getTask(Integer id);

    void addTask(Task task) throws Exception;

    void updateTask(Task task)  throws Exception;

    void deleteTask(Integer id)  throws Exception;

    Collection<Task> getTasks();
}

IMPL-------------------------------------------------------------------------------------

package fake.test.xa.internal;

import java.util.Collection;
import java.util.Date;

import javax.persistence.EntityManager;
import javax.persistence.criteria.CriteriaQuery;

import org.osgi.framework.BundleContext;
import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Deactivate;
import org.osgi.service.component.annotations.Reference;
import org.osgi.service.transaction.control.TransactionControl;
import org.osgi.service.transaction.control.jpa.JPAEntityManagerProvider;

import fake.test.xa.api.Task;
import fake.test.xa.api.TaskService;

@Component(immediate=true)
public class TaskServiceImpl implements TaskService {

TransactionControl txControl;

EntityManager em;
    @Reference
    void setTxControl(TransactionControl txControl) {
this.txControl = txControl;
}
    void unsetTxControl(TransactionControl txControl) {
this.txControl = null;
}

    @Reference(target = "(osgi.unit.name=tasklist)")
    void setProvider(JPAEntityManagerProvider provider) {
        em = provider.getResource(txControl);
    }

@Activate
private void activate(BundleContext ctx) {
        System.out.println("Starting the service "+ getClass().getName() +"
at "+new Date());
}
@Deactivate
private void deactivate(BundleContext ctx) {
        System.out.println("Stopping the service"+ getClass().getName() +"
at "+new Date());
}

    @Override
    public Task getTask(Integer id) {
        return  txControl.supports(() -> em.find(Task.class, id));
    }

    @Override
    public void addTask(Task task) throws Exception {
        if (task.getId() == null) {
            throw new Exception("Id property must be set");
        }
        System.err.println("Adding task " + task.getId());

        txControl.required(()-> {
            em.persist(task);
            em.flush();
        return null;
        });

    }

    public Collection<Task> getTasks() {
    return txControl.supports(() -> {
            CriteriaQuery<Task> query =
em.getCriteriaBuilder().createQuery(Task.class);
            return
em.createQuery(query.select(query.from(Task.class))).getResultList();
        });
    }

    @Override
    public void updateTask(Task task) throws Exception{
        if (task.getId() == null) {
            throw new Exception("Id property must be set");
        }
        System.err.println("Updating task " + task.getId());

        if(null==getTask(task.getId())) {
        throw new Exception("Task never registered before");
        }

        txControl.required(() -> {
        em.merge(task);
        em.flush();
        return null;
        });

    }

    @Override
   public void deleteTask(Integer id) throws Exception {
        System.err.println("Deleting task " + id);

        txControl.required(() -> {
    Task task = getTask(id);
            if (task  == null) {
            throw new RuntimeException("Task with id="+id+" not found");
            }
            em.remove(task);
    em.flush();
        return null;
        });

    }


}

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="tasklist" transaction-type="JTA">
        <provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
        <jta-data-source>osgi:service/javax.sql.DataSource/(
osgi.jndi.service.name=reactive)</jta-data-source>
        <properties>
            <property name="hibernate.dialect"
value="org.hibernate.dialect.MySQLDialect"/>
            <property name="hibernate.hbm2ddl.auto" value="create-drop"/>
        </properties>
    </persistence-unit>

</persistence>


POM.XML----------------------------------------------------

<project xmlns="http://maven.apache.org/POM/4.0.0"; xmlns:xsi="
http://www.w3.org/2001/XMLSchema-instance";
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd";>
<modelVersion>4.0.0</modelVersion>

<groupId>fake</groupId>
<artifactId>test.xa</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>fake.test.xa</name>
<packaging>bundle</packaging>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

<java.version>1.8</java.version>
<osgi.version>6.0.0</osgi.version>
<osgi.compendium.version>5.0.0</osgi.compendium.version>

<aries.jpa.version>2.2.0</aries.jpa.version>

<dosgi.version>2.3.0</dosgi.version>
<aQute.version>1.50.0</aQute.version>
<enroute.version>2.0.0</enroute.version>

<karaf.shell.console.version>4.0.3</karaf.shell.console.version>

<maven.bundle.plugin.version>3.3.0</maven.bundle.plugin.version>
<maven-resources-plugin.version>3.0.2</maven-resources-plugin.version>

<transaction.version>2.0.0</transaction.version>
<transaction-api.version>1.2</transaction-api.version>
<jdbc.version>1.2.1</jdbc.version>
<aries.tx.control.version>1.0.0</aries.tx.control.version>

<baseline.skip>true</baseline.skip>

<topDirectoryLocation>..</topDirectoryLocation>
</properties>

<dependencies>
<dependency>
<groupId>org.osgi</groupId>
<artifactId>osgi.core</artifactId>
<version>${osgi.version}</version>
</dependency>

<dependency>
<groupId>org.osgi</groupId>
<artifactId>osgi.cmpn</artifactId>
<version>${osgi.compendium.version}</version>
</dependency>

<dependency>
<groupId>biz.aQute</groupId>
<artifactId>bndlib</artifactId>
<version>${aQute.version}</version>
</dependency>

<dependency>
<groupId>org.osgi</groupId>
<artifactId>osgi.enroute.base.api</artifactId>
<version>${enroute.version}</version>
</dependency>

<dependency>
<groupId>org.apache.karaf.shell</groupId>
<artifactId>org.apache.karaf.shell.console</artifactId>
<version>${karaf.shell.console.version}</version>
</dependency>

<dependency>
<groupId>javax.transaction</groupId>
<artifactId>javax.transaction-api</artifactId>
<version>${transaction-api.version}</version>
</dependency>

<dependency>
<groupId>org.apache.aries.jpa</groupId>
<artifactId>org.apache.aries.jpa.api</artifactId>
<version>${aries.jpa.version}</version>
</dependency>
<dependency>
<groupId>org.apache.aries.jpa</groupId>
<artifactId>org.apache.aries.jpa.support</artifactId>
<version>${aries.jpa.version}</version>
</dependency>


<dependency>
<groupId>org.hibernate.javax.persistence</groupId>
<artifactId>hibernate-jpa-2.1-api</artifactId>
<version>1.0.0.Final</version>
</dependency>

<dependency>
<groupId>org.apache.aries.tx-control</groupId>
<artifactId>tx-control-service-xa</artifactId>
<version>${aries.tx.control.version}</version>
</dependency>
<dependency>
<groupId>org.apache.aries.tx-control</groupId>
<artifactId>tx-control-provider-jpa-xa</artifactId>
<version>${aries.tx.control.version}</version>
</dependency>
</dependencies>




<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>

<pluginManagement>
<plugins>

<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<version>${maven.bundle.plugin.version}</version>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>${maven-resources-plugin.version}</version>
</plugin>
</plugins>
</pluginManagement>

<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
</plugin>

<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<extensions>true</extensions>
<configuration>
<instructions>
<_include>-bnd.bnd</_include>
<Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
<Bundle-Version>${project.version}</Bundle-Version>
<Service-Component>*</Service-Component>
<Bundle-Activator>fake.test.xa.internal.Activator</Bundle-Activator>
<!-- <Export-Package>fake.test.xa.*;version=${project.version}
</Export-Package> -->
<Import-Package>*</Import-Package>
<Meta-Persistence>META-INF/persistence.xml</Meta-Persistence>
</instructions>
</configuration>
</plugin>

</plugins>
</build>
</project>

-----------------------------------------------------------------


karaf@test()> diag 98
fake.test.xa (98)
-----------------
Status: Waiting
Declarative Services
xa.command (9)
  missing references: TaskService
fake.test.xa.internal.TaskServiceImpl (8)
  missing references: Provider



karaf@test()> feature:list -i
Name                         | Version     | Required | State   |
Repository               | Description
-----------------------------+-------------+----------+---------+--------------------------+--------------------------------------------------
aries-proxy                  | 4.2.0.M1    |          | Started |
standard-4.2.0.M1        | Aries Proxy
feature                      | 4.2.0.M1    | x        | Started |
standard-4.2.0.M1        | Features Support
shell                        | 4.2.0.M1    | x        | Started |
standard-4.2.0.M1        | Karaf Shell
deployer                     | 4.2.0.M1    | x        | Started |
standard-4.2.0.M1        | Karaf Deployer
bundle                       | 4.2.0.M1    | x        | Started |
standard-4.2.0.M1        | Provide Bundle support
config                       | 4.2.0.M1    | x        | Started |
standard-4.2.0.M1        | Provide OSGi ConfigAdmin support
diagnostic                   | 4.2.0.M1    | x        | Started |
standard-4.2.0.M1        | Provide Diagnostic support
instance                     | 4.2.0.M1    | x        | Started |
standard-4.2.0.M1        | Provide Instance support
jaas                         | 4.2.0.M1    | x        | Started |
standard-4.2.0.M1        | Provide JAAS support
log                          | 4.2.0.M1    | x        | Started |
standard-4.2.0.M1        | Provide Log support
package                      | 4.2.0.M1    | x        | Started |
standard-4.2.0.M1        | Package commands and mbeans
service                      | 4.2.0.M1    | x        | Started |
standard-4.2.0.M1        | Provide Service support
system                       | 4.2.0.M1    | x        | Started |
standard-4.2.0.M1        | Provide System support
kar                          | 4.2.0.M1    | x        | Started |
standard-4.2.0.M1        | Provide KAR (KARaf archive) support
ssh                          | 4.2.0.M1    | x        | Started |
standard-4.2.0.M1        | Provide a SSHd server on Karaf
management                   | 4.2.0.M1    | x        | Started |
standard-4.2.0.M1        | Provide a JMX MBeanServer and a set of MBeans in
eventadmin                   | 4.2.0.M1    | x        | Started |
standard-4.2.0.M1        | OSGi Event Admin service specification for event-
scr                          | 4.2.0.M1    | x        | Started |
standard-4.2.0.M1        | Declarative Service support
wrap                         | 2.5.3       | x        | Started |
standard-4.2.0.M1        | Wrap URL handler
pax-transx-tm-api            | 0.2.0       |          | Started |
pax-transx-0.2.0         |
pax-transx-tm-geronimo       | 0.2.0       |          | Started |
pax-transx-0.2.0         |
hibernate-orm                | 5.2.8.Final |          | Started |
hibernate-osgi           | Combines all Hibernate core dependencies and requ
transaction-api              | 1.2.0       |          | Started |
enterprise-4.2.0.M1      |
transaction-manager-geronimo | 3.1.3       |          | Started |
enterprise-4.2.0.M1      | Geronimo Transaction Manager
transaction                  | 2.0.0       | x        | Started |
enterprise-4.2.0.M1      | OSGi Transaction Manager
hibernate                    | 5.2.8.Final | x        | Started |
enterprise-4.2.0.M1      | Hibernate JPA engine support
jndi                         | 4.2.0.M1    | x        | Started |
enterprise-4.2.0.M1      | OSGi Service Registry JNDI access
jdbc                         | 4.2.0.M1    | x        | Started |
enterprise-4.2.0.M1      | JDBC service and commands
pax-jdbc-spec                | 1.2.0       |          | Started |
org.ops4j.pax.jdbc-1.2.0 | Provides OSGi JDBC Service spec
pax-jdbc                     | 1.2.0       |          | Started |
org.ops4j.pax.jdbc-1.2.0 | Provides JDBC Service support
pax-jdbc-config              | 1.2.0       |          | Started |
org.ops4j.pax.jdbc-1.2.0 | Provides JDBC Config support
pax-jdbc-mysql               | 1.2.0       | x        | Started |
org.ops4j.pax.jdbc-1.2.0 | Provides JDBC MySQL DataSourceFactory
pax-jdbc-pool-dbcp2          | 1.2.0       | x        | Started |
org.ops4j.pax.jdbc-1.2.0 | Provides JDBC Pooling DataSourceFactory
jpa                          | 2.6.1       | x        | Started |
aries-jpa-2.6.1          | OSGi Persistence Container


karaf@test()> list -u
START LEVEL 100 , List Threshold: 50
ID | State    | Lvl | Version            | Update location
---+----------+-----+--------------------+----------------------------------------------------------------------------------------------------------------------------
20 | Resolved |  80 | 4.2.0.M1           |
mvn:org.apache.karaf.diagnostic/org.apache.karaf.diagnostic.boot/4.2.0.M1
22 | Active   |  80 | 4.2.0.M1           |
mvn:org.apache.karaf/org.apache.karaf.event/4.2.0.M1
43 | Active   |  80 | 1.9.2.1            |
mvn:org.apache.servicemix.bundles/org.apache.servicemix.bundles.jasypt/1.9.2_1
44 | Active   |  80 | 1.2.0              |
mvn:org.ops4j.pax.jdbc/pax-jdbc/1.2.0
45 | Active   |  80 | 1.2.0              |
mvn:org.ops4j.pax.jdbc/pax-jdbc-config/1.2.0
46 | Active   |  80 | 1.2.0              |
mvn:org.ops4j.pax.jdbc/pax-jdbc-pool-common/1.2.0
47 | Active   |  80 | 1.0.0.201505202023 |
mvn:org.osgi/org.osgi.service.jdbc/1.0.0
48 | Active   |  80 | 1.3.0              | mvn:com.fasterxml/classmate/1.3.0
49 | Active   |  80 | 5.1.34             |
mvn:mysql/mysql-connector-java/5.1.34
50 | Active   |  80 | 3.20.0.GA          |
mvn:org.javassist/javassist/3.20.0-GA
51 | Active   |  80 | 3.0.0              | mvn:javax.el/javax.el-api/3.0.0
52 | Active   |  80 | 1.2.0              | mvn:javax.enterprise/cdi-api/1.2
53 | Active   |  80 | 1.2                |
mvn:javax.interceptor/javax.interceptor-api/1.2
55 | Active   |  80 | 1.2                |
mvn:javax.transaction/javax.transaction-api/1.2
56 | Active   |  80 | 1.6.6              |
mvn:net.bytebuddy/byte-buddy/1.6.6
67 | Active   |  80 | 4.2.0.M1           |
mvn:org.apache.karaf.jdbc/org.apache.karaf.jdbc.core/4.2.0.M1
69 | Active   |  80 | 2.7.7.5            |
mvn:org.apache.servicemix.bundles/org.apache.servicemix.bundles.antlr/2.7.7_5
70 | Active   |  80 | 1.6.1.5            |
mvn:org.apache.servicemix.bundles/org.apache.servicemix.bundles.dom4j/1.6.1_5
71 | Active   |  80 | 1.0.0.2            |
mvn:org.apache.servicemix.bundles/org.apache.servicemix.bundles.javax-inject/1_2
73 | Active   |  80 | 5.0.1.Final        |
mvn:org.hibernate.common/hibernate-commons-annotations/5.0.1.Final
74 | Active   |  80 | 5.2.8.Final        |
mvn:org.hibernate/hibernate-core/5.2.8.Final
75 | Active   |  80 | 5.2.8.Final        |
mvn:org.hibernate/hibernate-osgi/5.2.8.Final
76 | Active   |  80 | 2.0.3.Final        | mvn:org.jboss/jandex/2.0.3.Final
77 | Active   |  80 | 3.3.0.Final        |
mvn:org.jboss.logging/jboss-logging/3.3.0.Final
79 | Active   |  80 | 1.2.0              |
mvn:org.ops4j.pax.jdbc/pax-jdbc-mysql/1.2.0
80 | Active   |  80 | 0.2.0              |
mvn:org.ops4j.pax.transx/pax-transx-tm-api/0.2.0
81 | Active   |  80 | 0.2.0              |
mvn:org.ops4j.pax.transx/pax-transx-tm-geronimo/0.2.0
82 | Active   |  80 | 1.0.0              |
mvn:org.apache.aries.tx-control/tx-control-service-xa/1.0.0
83 | Active   |  80 | 1.0.0              |
mvn:org.apache.aries.tx-control/tx-control-provider-jdbc-xa/1.0.0
84 | Active   |  80 | 1.0.0              |
mvn:org.apache.aries.tx-control/tx-control-provider-jpa-xa/1.0.0
92 | Active   |  80 | 2.7.1.SNAPSHOT     |
mvn:org.apache.aries.jpa.javax.persistence/javax.persistence_2.1/2.7.1-SNAPSHOT
94 | Active   |  80 | 2.1.1              |
mvn:org.apache.commons/commons-dbcp2/2.1.1
95 | Active   |  80 | 2.4.2              |
mvn:org.apache.commons/commons-pool2/2.4.2
96 | Active   |  80 | 3.2.4.1            |
mvn:org.apache.servicemix.bundles/org.apache.servicemix.bundles.cglib/3.2.4_1
97 | Active   |  80 | 1.2.0              |
mvn:org.ops4j.pax.jdbc/pax-jdbc-pool-dbcp2/1.2.0
98 | Waiting  |  80 | 0.0.1.SNAPSHOT     |
file:/C:/KARAF/apache-karaf-4.2.0.M1/instances/test/deploy/test.xa-0.0.1-SNAPSHOT.jar

Reply via email to