0

I have been using EclipseLink JPA 2.1 for a year now. I know that this problem has been asked before, I have seen this, this, this, this, and this.

I was running on a JDK 8, Tomcat 8 and EclipseLink JPA 2.1 for over a year now. Everything about JPA was running smoothly. We decided to move to a JDK 11 server running on Tomcat 9. I encountered some errors and decided to update my EcliseLink JPA libraries to EcliseLink 3.0.0

Now I am getting this error on a JPA project that was running smoothly for over a year:

16-Dec-2020 10:23:45.111 SEVERE [main] org.apache.catalina.core.StandardContext.listenerStart Exception sending context initialized event to listener instance of class [admin.zaapmart.ContextListener]
javax.persistence.PersistenceException: No Persistence provider for EntityManager named ZaapMartPU
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:85)
at admin.zaapmart.ContextListener.loadRemoteEntityManagerFactory(ContextListener.java:192)
at admin.zaapmart.ContextListener.contextInitialized(ContextListener.java:120)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4668)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5136)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:713)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:690)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:695)
at org.apache.catalina.startup.HostConfig.deployDescriptor(HostConfig.java:631)
at org.apache.catalina.startup.HostConfig$DeployDescriptor.run(HostConfig.java:1832)
at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
at org.apache.tomcat.util.threads.InlineExecutorService.execute(InlineExecutorService.java:75)
at java.base/java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:118)
at org.apache.catalina.startup.HostConfig.deployDescriptors(HostConfig.java:526)
at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:425)
at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1577)
at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:309)
at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:123)
at org.apache.catalina.util.LifecycleBase.setStateInternal(LifecycleBase.java:424)
at org.apache.catalina.util.LifecycleBase.setState(LifecycleBase.java:367)
at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:929)
at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:831)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1377)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1367)
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
at org.apache.tomcat.util.threads.InlineExecutorService.execute(InlineExecutorService.java:75)
at java.base/java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:140)
at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:902)
at org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.java:262)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
at org.apache.catalina.core.StandardService.startInternal(StandardService.java:423)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
at org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:928)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
at org.apache.catalina.startup.Catalina.start(Catalina.java:638)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:350)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:492)

The WebApplicationListener class that throws this error:

/**
 * Web application lifecycle listener.
 *
 * @author Jevison7x
 */
public class ContextListener implements ServletContextListener
{
    ...

    @Override
    public void contextInitialized(ServletContextEvent sce)
    {
        ...
        this.loadRemoteEntityManagerFactory();
        ...
    }
    
    private void loadRemoteEntityManagerFactory()
    {
        Map<String, String> persistenceMap = new HashMap<>();
        persistenceMap.put("javax.persistence.jdbc.url", remoteDBProperties.getProperty("zaapmart_db.url"));
        persistenceMap.put("javax.persistence.jdbc.user", remoteDBProperties.getProperty("db.user"));
        persistenceMap.put("javax.persistence.jdbc.password", remoteDBProperties.getProperty("db.pass"));
        persistenceMap.put("javax.persistence.jdbc.driver", remoteDBProperties.getProperty("driverName"));
        //Next line throws the Error
        DBConfiguration.remoteEntityManagerFactory = Persistence.createEntityManagerFactory("ZaapMartPU", persistenceMap);
    }
...

This is my persistence.xml file:

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
    <persistence-unit name="ZaapMartPU" transaction-type="RESOURCE_LOCAL">
        <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
        <class>com.zaapmart.purchases.Transaction</class>
        <class>com.zaapmart.products.Category</class>
        <class>com.zaapmart.products.Product</class>
        <class>com.zaapmart.products.ProductImage</class>
        <class>com.zaapmart.products.SubCategory</class>
        <class>com.zaapmart.purchases.OrderItem</class>
        <class>com.zaapmart.users.User</class>
        <class>com.zaapmart.users.Supplier</class>
        <class>com.zaapmart.wallet.Voucher</class>
        <class>com.zaapmart.purchases.TransactionHistory</class>
        <class>com.zaapmart.wallet.VirtualWallet</class>
        <class>com.zaapmart.wallet.WalletPOP</class>
        <class>com.zaapmart.wallet.WalletTransaction</class>
        <exclude-unlisted-classes>false</exclude-unlisted-classes>
        <properties>
            <property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/xxx_zaapmart"/>
            <property name="javax.persistence.jdbc.user" value="bahaushi_zaapapp"/>
            <property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"/>
            <property name="javax.persistence.jdbc.password" value="xxxxxxx"/>
        </properties>
    </persistence-unit>
</persistence>

I think persistence.xml is in the right location:

Project Directories

Here is my list of Libraries:

Libraries

EclipseLink 3.0.0 Classpath:

EclipseLink Classpath

I downloaded EclipsLink from here.

Can someone please tell me what is wrong here?

Jevison7x
  • 709
  • 2
  • 14
  • 31
  • you changed everything about this project - the JDK, container and provider jars - so you can't really say it was running smoothly for a year. Change one thing at a time incrementally to see which is the problem piece. The error in this case is stating it can't find the EclipseLink jars, so the problem will be with changes in the container loading from past release or the setup differences between them. Also make sure to turn logging on, as EclipseLink should log if it is even being called, giving you away to rule out errors when it is loading. – Chris Dec 16 '20 at 14:59
  • Hello @Chris, please how do I enable logging on JPA? I've never done that before. – Jevison7x Dec 16 '20 at 18:01

0 Answers0