Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Newcomers » Newcomers » javax.persistence.PersistenceException: No Persistence provider for EntityManager named XXXX
javax.persistence.PersistenceException: No Persistence provider for EntityManager named XXXX [message #1739359] Sat, 30 July 2016 14:18
dheeraj lalwani is currently offline dheeraj lalwaniFriend
Messages: 1
Registered: July 2016
Location: india
Junior Member
I am trying to create a simple osgi bundle jax-rs rest service with eclipselink but getting error javax.persistence.PersistenceException: No Persistence provider for EntityManager named persistenceUnit I have specified the eclipselink provider in the persistence.xml also persistence.xml location is also there in MANIFEST.MF.

Any help on this would be greatly appreciated.

PFB My Configuration-

pom.xml

<project>
<modelVersion>4.0.0</modelVersion>
<groupId>com.test.servicemix</groupId>
<artifactId>servicemix</artifactId>
<version>1.0</version>
<packaging>bundle</packaging>

<properties>
    <cxf.version>2.7.11</cxf.version>
</properties>
<dependencies>
    <!-- <dependency> <groupId>karafcxf</groupId> <artifactId>karafcxf.service.impl</artifactId> 
        <version>1.0-SNAPSHOT</version> </dependency> -->
    <dependency>
        <groupId>org.apache.cxf</groupId>
        <artifactId>cxf-rt-frontend-jaxws</artifactId>
        <version>2.7.11</version>
    </dependency>
    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <version>5.1.6</version>
    </dependency>
    <dependency>
        <groupId>org.apache.cxf</groupId>
        <artifactId>cxf-rt-frontend-jaxrs</artifactId>
        <version>2.7.11</version>
    </dependency>
    <dependency>
        <groupId>org.eclipse.persistence</groupId>
        <artifactId>eclipselink</artifactId>
        <version>2.4.2</version>
        <exclusions>
            <exclusion>
                <groupId>org.eclipse.persistence</groupId>
                <artifactId>commonj.sdo</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>org.eclipse.persistence</groupId>
        <artifactId>javax.persistence</artifactId>
        <version>2.1.0</version>
    </dependency>
    <dependency>
        <groupId>org.osgi</groupId>
        <artifactId>org.osgi.core</artifactId>
        <version>4.3.1</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>org.osgi</groupId>
        <artifactId>org.osgi.compendium</artifactId>
        <version>4.3.1</version>
        <scope>runtime</scope>
    </dependency>
    <dependency>
        <groupId>org.ow2.asm</groupId>
        <artifactId>asm-commons</artifactId>
        <version>5.0.3</version>
        <scope>runtime</scope>
    </dependency>
    <dependency>
        <groupId>asm</groupId>
        <artifactId>asm</artifactId>
        <version>3.3.1</version>
    </dependency>
    <dependency>
        <groupId>org.eclipse.persistence</groupId>
        <artifactId>commonj.sdo</artifactId>
        <version>2.1.1</version>
    </dependency>
    <dependency>
        <groupId>javax.validation</groupId>
        <artifactId>validation-api</artifactId>
        <version>1.1.0.Final</version>
    </dependency>
    <dependency>
        <groupId>org.eclipse.persistence</groupId>
        <artifactId>org.eclipse.persistence.oracle</artifactId>
        <version>2.4.2</version>
    </dependency>
</dependencies>
<build>
    <plugins>
        <plugin>
            <groupId>org.apache.felix</groupId>
            <artifactId>maven-bundle-plugin</artifactId>
            <version>2.3.7</version>
            <extensions>true</extensions>
            <configuration>
                <manifestLocation>src/main/resources/META-INF</manifestLocation>
                <instructions>
                    <Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
                    <Bundle-Version>${project.version}</Bundle-Version>
                    <Meta-Persistence>META-INF/persistence.xml</Meta-Persistence>
                    <Bundle-Activator>com.test.servicemix.BundleStartupListener</Bundle-Activator>
                    <Export-Package>com.test.model</Export-Package>
                    <Import-Package>
                    org.osgi.service.blueprint;resolution:=optional,
                    org.apache.felix.service.command,
                    org.apache.felix.gogo.commands,
                    org.apache.karaf.shell.console,
                    *,!javax.persistence
                    </Import-Package>
                    <Embed-Dependency>javax.persistence</Embed-Dependency>
                </instructions>
            </configuration>
        </plugin>
    </plugins>
</build>


blueprint.xml (rest.xml)-

<blueprint>

    <bean id="jpaProvider" class="org.eclipse.persistence.jpa.PersistenceProvider" />  

    <service ref="jpaProvider" interface="javax.persistence.spi.PersistenceProvider">
     <service-properties>
            <entry key="javax.persistence.provider" value="org.eclipse.persistence.jpa.PersistenceProvider"/>
     </service-properties>
    </service>
    <cxf:bus id="cxfBus1">
        <cxf:features>
            <cxf:logging/>
        </cxf:features>
    </cxf:bus>


    <jaxrs:server address="/servicemix" id="someRestService">
        <jaxrs:serviceBeans>
            <ref component-id="testServiceImpl"/>
        </jaxrs:serviceBeans>
    </jaxrs:server>


    <!-- Implementation of the rest service -->
    <bean id="testServiceImpl" class="com.test.servicemix.TestServiceImpl">

    </bean>


</blueprint>


BundleStartupListener.java

package com.test.servicemix;

import java.util.Dictionary;
import java.util.Hashtable;

import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceRegistration;

public class BundleStartupListener implements BundleActivator {

    private ServiceRegistration serviceRegistration;
    private static final String JAVAX_PERSISTENCE_PROVIDER_PROP = "javax.persistence.provider";

    public void start(BundleContext context) {
        System.out.println("Starting my bundle");
        org.eclipse.persistence.jpa.PersistenceProvider persistence = new org.eclipse.persistence.jpa.PersistenceProvider();
        Dictionary<String, String> props = new Hashtable<String, String>();
        props.put(JAVAX_PERSISTENCE_PROVIDER_PROP, persistence.getClass().getName());
        serviceRegistration = context.registerService(persistence.getClass().getName(), persistence, props);
    }

    public void stop(BundleContext context) {
        System.out.println("Stopping my bundle");
        serviceRegistration.unregister();
    }
}


TestService.java

package com.test.servicemix;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.core.Response;

@Path("test")
public interface TestService {

    @GET
    @Path("hello")
    public Response handleGet();

}


TestServiceImpl.java

    package com.test.servicemix;

import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import javax.ws.rs.core.CacheControl;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.ResponseBuilder;

import com.test.model.User;;

public class TestServiceImpl implements TestService{

    private EntityManager entityManager;

    public TestServiceImpl(){
    }

    public Response handleGet(){

         EntityManagerFactory factory = Persistence.createEntityManagerFactory("persistenceUnit");
         entityManager = factory.createEntityManager();
         List<User> resultList = entityManager.createQuery("Select a From User a WHERE a.userId between 1 AND 20", User.class).getResultList();
         for (User user : resultList) {
             System.out.println("next user: " + user.getId() +":"+ user.getSurname());
         }
        CacheControl cc= new CacheControl();
        cc.setMaxAge(300000);
        ResponseBuilder builder= Response.ok("Namaste user");
        builder.cacheControl(cc);
        return builder.build();
    }
}


MANIFEST.MF

Manifest-Version: 1.0
Bnd-LastModified: 1469884319031
Build-Jdk: 1.7.0_79
Built-By: HP
Bundle-Activator: com.test.servicemix.BundleStartupListener
Bundle-ClassPath: .,javax.persistence-2.1.0.jar
Bundle-ManifestVersion: 2
Bundle-Name: servicemix
Bundle-SymbolicName: servicemix
Bundle-Version: 1.0
Created-By: Apache Maven Bundle Plugin
Embed-Dependency: javax.persistence
Embedded-Artifacts: javax.persistence-2.1.0.jar;g="org.eclipse.persisten
 ce";a="javax.persistence";v="2.1.0"
Export-Package: com.test.model;version="1.0"
Export-Service: javax.persistence.spi.PersistenceProvider;javax.persiste
 nce.provider="org.eclipse.persistence.jpa.PersistenceProvider"
Import-Package: javax.sql,javax.ws.rs;version="[2.0,3)",javax.ws.rs.core
 ;version="[2.0,3)",org.apache.felix.gogo.commands,org.apache.felix.serv
 ice.command,org.apache.karaf.shell.console,org.eclipse.persistence.jpa,
 org.osgi.framework;version="[1.6,2)",org.osgi.service.blueprint;resolut
 ion:=optional;version="[1.0.0,2.0.0)"
Meta-Persistence: META-INF/persistence.xml
Originally-Created-By: Apache Maven Bundle Plugin
Tool: Bnd-1.50.0


User.java

package com.test.model;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;

@Entity
@Table(name="person")
public class User implements Serializable{

    private static final long serialVersionUID = 1L;

    @Id
    @Column(name="UserID")
    private int id;

    @Column(name="Surname")
    private String surname;

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getSurname() {
        return surname;
    }

    public void setSurname(String surname) {
        this.surname = surname;
    }
}


Karaf Logs-

2016-07-30 18:42:12,222 | INFO  | -SNAPSHOT/deploy | fileinstall                      | 8 - org.apache.felix.fileinstall - 3.5.0 | Updating bundle servicemix / 1.0.0
2016-07-30 18:42:12,223 | INFO  | -SNAPSHOT/deploy | BlueprintExtender                | 19 - org.apache.aries.blueprint.core - 1.4.3 | Destroying BlueprintContainer for bundle servicemix
2016-07-30 18:42:12,310 | INFO  | -SNAPSHOT/deploy | InstrumentationManagerImpl       | 144 - org.apache.cxf.cxf-core - 3.1.5 | registering MBean org.apache.cxf:bus.id=cxfBus1,type=Bus,instance.id=1728551857: org.apache.cxf.bus.ManagedBus@247eb64f
2016-07-30 18:42:12,311 | INFO  | -SNAPSHOT/deploy | InstrumentationManagerImpl       | 144 - org.apache.cxf.cxf-core - 3.1.5 | registering MBean org.apache.cxf:bus.id=cxfBus1,type=Bus,instance.id=1728551857: javax.management.modelmbean.RequiredModelMBean@7af30f40
2016-07-30 18:42:12,312 | INFO  | -SNAPSHOT/deploy | InstrumentationManagerImpl       | 144 - org.apache.cxf.cxf-core - 3.1.5 | registered org.apache.cxf:bus.id=cxfBus1,type=Bus,instance.id=1728551857
2016-07-30 18:42:12,313 | INFO  | -SNAPSHOT/deploy | InstrumentationManagerImpl       | 144 - org.apache.cxf.cxf-core - 3.1.5 | registering MBean org.apache.cxf:bus.id=cxfBus1,WorkQueueManager=Bus.WorkQueueManager,type=WorkQueueManager,instance.id=1802400207: org.apache.cxf.bus.managers.WorkQueueManagerImplMBeanWrapper@1ff20423
2016-07-30 18:42:12,314 | INFO  | -SNAPSHOT/deploy | InstrumentationManagerImpl       | 144 - org.apache.cxf.cxf-core - 3.1.5 | registering MBean org.apache.cxf:bus.id=cxfBus1,WorkQueueManager=Bus.WorkQueueManager,type=WorkQueueManager,instance.id=1802400207: javax.management.modelmbean.RequiredModelMBean@49eda637
2016-07-30 18:42:12,321 | INFO  | -SNAPSHOT/deploy | ServerImpl                       | 144 - org.apache.cxf.cxf-core - 3.1.5 | Setting the server's publish address to be /servicemix
2016-07-30 18:42:12,322 | INFO  | -SNAPSHOT/deploy | InstrumentationManagerImpl       | 144 - org.apache.cxf.cxf-core - 3.1.5 | registering MBean org.apache.cxf:bus.id=cxfBus1,type=Bus.Service.Endpoint,service="{}TestServiceImpl",port="TestServiceImpl",instance.id=1061427707: org.apache.cxf.endpoint.ManagedEndpoint@1005ce30
2016-07-30 18:42:12,323 | INFO  | -SNAPSHOT/deploy | InstrumentationManagerImpl       | 144 - org.apache.cxf.cxf-core - 3.1.5 | registering MBean org.apache.cxf:bus.id=cxfBus1,type=Bus.Service.Endpoint,service="{}TestServiceImpl",port="TestServiceImpl",instance.id=1061427707: javax.management.modelmbean.RequiredModelMBean@6d23b987
2016-07-30 18:42:12,334 | INFO  | -SNAPSHOT/deploy | fileinstall                      | 8 - org.apache.felix.fileinstall - 3.5.0 | Started bundle: file:/E:/apache-servicemix-5.6.2-SNAPSHOT/deploy/servicemix-1.0.jar
2016-07-30 18:42:23,138 | INFO  | qtp41019454-75   | LoggingInInterceptor             | 144 - org.apache.cxf.cxf-core - 3.1.5 | Inbound Message
----------------------------
ID: 10
Address: cxf/servicemix/test/hello
Http-Method: GET
Content-Type: 
Headers: {Accept=[text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8], accept-encoding=[gzip, deflate, sdch], Accept-Language=[en-US,en;q=0.8], Cache-Control=[max-age=0], connection=[keep-alive], Content-Type=[null], Host=[localhost:8181], Upgrade-Insecure-Requests=[1], User-Agent=[Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36]}
--------------------------------------
2016-07-30 18:42:23,143 | WARN  | qtp41019454-75   | PhaseInterceptorChain            | 144 - org.apache.cxf.cxf-core - 3.1.5 | Application {}TestServiceImpl has thrown exception, unwinding now
org.apache.cxf.interceptor.Fault: No Persistence provider for EntityManager named persistenceUnit
    at org.apache.cxf.service.invoker.AbstractInvoker.createFault(AbstractInvoker.java:162)[144:org.apache.cxf.cxf-core:3.1.5]
    at org.apache.cxf.service.invoker.AbstractInvoker.invoke(AbstractInvoker.java:128)[144:org.apache.cxf.cxf-core:3.1.5]
    at org.apache.cxf.jaxrs.JAXRSInvoker.invoke(JAXRSInvoker.java:189)[157:org.apache.cxf.cxf-rt-frontend-jaxrs:3.1.5]
    at org.apache.cxf.jaxrs.JAXRSInvoker.invoke(JAXRSInvoker.java:99)[157:org.apache.cxf.cxf-rt-frontend-jaxrs:3.1.5]
    at org.apache.cxf.interceptor.ServiceInvokerInterceptor$1.run(ServiceInvokerInterceptor.java:59)[144:org.apache.cxf.cxf-core:3.1.5]
    at org.apache.cxf.interceptor.ServiceInvokerInterceptor.handleMessage(ServiceInvokerInterceptor.java:96)[144:org.apache.cxf.cxf-core:3.1.5]
    at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:308)[144:org.apache.cxf.cxf-core:3.1.5]
    at org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:121)[144:org.apache.cxf.cxf-core:3.1.5]
    at org.apache.cxf.transport.http.AbstractHTTPDestination.invoke(AbstractHTTPDestination.java:253)[151:org.apache.cxf.cxf-rt-transports-http:3.1.5]
    at org.apache.cxf.transport.servlet.ServletController.invokeDestination(ServletController.java:234)[151:org.apache.cxf.cxf-rt-transports-http:3.1.5]
    at org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:208)[151:org.apache.cxf.cxf-rt-transports-http:3.1.5]
    at org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:160)[151:org.apache.cxf.cxf-rt-transports-http:3.1.5]
    at org.apache.cxf.transport.servlet.CXFNonSpringServlet.invoke(CXFNonSpringServlet.java:180)[151:org.apache.cxf.cxf-rt-transports-http:3.1.5]
    at org.apache.cxf.transport.servlet.AbstractHTTPServlet.handleRequest(AbstractHTTPServlet.java:298)[151:org.apache.cxf.cxf-rt-transports-http:3.1.5]
    at org.apache.cxf.transport.servlet.AbstractHTTPServlet.doGet(AbstractHTTPServlet.java:222)[151:org.apache.cxf.cxf-rt-transports-http:3.1.5]
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:575)[59:org.apache.geronimo.specs.geronimo-servlet_3.0_spec:1.0.0]
    at org.apache.cxf.transport.servlet.AbstractHTTPServlet.service(AbstractHTTPServlet.java:273)[151:org.apache.cxf.cxf-rt-transports-http:3.1.5]
    at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:684)[64:org.eclipse.jetty.aggregate.jetty-all-server:8.1.17.v20150415]
    at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:503)[64:org.eclipse.jetty.aggregate.jetty-all-server:8.1.17.v20150415]
    at org.ops4j.pax.web.service.jetty.internal.HttpServiceServletHandler.doHandle(HttpServiceServletHandler.java:69)[73:org.ops4j.pax.web.pax-web-jetty:3.2.4]
    at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:137)[64:org.eclipse.jetty.aggregate.jetty-all-server:8.1.17.v20150415]
    at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:557)[64:org.eclipse.jetty.aggregate.jetty-all-server:8.1.17.v20150415]
    at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:231)[64:org.eclipse.jetty.aggregate.jetty-all-server:8.1.17.v20150415]
    at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1086)[64:org.eclipse.jetty.aggregate.jetty-all-server:8.1.17.v20150415]
    at org.ops4j.pax.web.service.jetty.internal.HttpServiceContext.doHandle(HttpServiceContext.java:240)[73:org.ops4j.pax.web.pax-web-jetty:3.2.4]
    at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:429)[64:org.eclipse.jetty.aggregate.jetty-all-server:8.1.17.v20150415]
    at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:193)[64:org.eclipse.jetty.aggregate.jetty-all-server:8.1.17.v20150415]
    at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1020)[64:org.eclipse.jetty.aggregate.jetty-all-server:8.1.17.v20150415]
    at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:135)[64:org.eclipse.jetty.aggregate.jetty-all-server:8.1.17.v20150415]
    at org.ops4j.pax.web.service.jetty.internal.JettyServerHandlerCollection.handle(JettyServerHandlerCollection.java:75)[73:org.ops4j.pax.web.pax-web-jetty:3.2.4]
    at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:116)[64:org.eclipse.jetty.aggregate.jetty-all-server:8.1.17.v20150415]
    at org.eclipse.jetty.server.Server.handle(Server.java:370)[64:org.eclipse.jetty.aggregate.jetty-all-server:8.1.17.v20150415]
    at org.eclipse.jetty.server.AbstractHttpConnection.handleRequest(AbstractHttpConnection.java:494)[64:org.eclipse.jetty.aggregate.jetty-all-server:8.1.17.v20150415]
    at org.eclipse.jetty.server.AbstractHttpConnection.headerComplete(AbstractHttpConnection.java:971)[64:org.eclipse.jetty.aggregate.jetty-all-server:8.1.17.v20150415]
    at org.eclipse.jetty.server.AbstractHttpConnection$RequestHandler.headerComplete(AbstractHttpConnection.java:1033)[64:org.eclipse.jetty.aggregate.jetty-all-server:8.1.17.v20150415]
    at org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:644)[64:org.eclipse.jetty.aggregate.jetty-all-server:8.1.17.v20150415]
    at org.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:235)[64:org.eclipse.jetty.aggregate.jetty-all-server:8.1.17.v20150415]
    at org.eclipse.jetty.server.AsyncHttpConnection.handle(AsyncHttpConnection.java:82)[64:org.eclipse.jetty.aggregate.jetty-all-server:8.1.17.v20150415]
    at org.eclipse.jetty.io.nio.SelectChannelEndPoint.handle(SelectChannelEndPoint.java:696)[64:org.eclipse.jetty.aggregate.jetty-all-server:8.1.17.v20150415]
    at org.eclipse.jetty.io.nio.SelectChannelEndPoint$1.run(SelectChannelEndPoint.java:53)[64:org.eclipse.jetty.aggregate.jetty-all-server:8.1.17.v20150415]
    at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:608)[64:org.eclipse.jetty.aggregate.jetty-all-server:8.1.17.v20150415]
    at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:543)[64:org.eclipse.jetty.aggregate.jetty-all-server:8.1.17.v20150415]
    at java.lang.Thread.run(Thread.java:745)[:1.7.0_79]
Caused by: javax.persistence.PersistenceException: No Persistence provider for EntityManager named persistenceUnit
    at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:85)[251:servicemix:1.0.0]
    at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:54)[251:servicemix:1.0.0]
    at com.test.servicemix.TestServiceImpl.handleGet(TestServiceImpl.java:23)[251:servicemix:1.0.0]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)[:1.7.0_79]
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)[:1.7.0_79]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)[:1.7.0_79]
    at java.lang.reflect.Method.invoke(Method.java:606)[:1.7.0_79]
    at org.apache.cxf.service.invoker.AbstractInvoker.performInvocation(AbstractInvoker.java:180)[144:org.apache.cxf.cxf-core:3.1.5]
    at org.apache.cxf.service.invoker.AbstractInvoker.invoke(AbstractInvoker.java:96)[144:org.apache.cxf.cxf-core:3.1.5]
    ... 41 more


Dheeraj Lalwani
Previous Topic:Eclipse crashes when attempting to load Lynda's exercise files
Next Topic:Hyperlink Navigation on MAC Using CTRL Key
Goto Forum:
  


Current Time: Tue Jun 25 13:47:41 GMT 2019

Powered by FUDForum. Page generated in 0.02918 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top