title: PersistenceException: No Persistence provider for EntityManager from Glassfish EJB module
body: <p>This EJB module is aimed at moving the database connection from the client to server-side to <a href="https://codereview.stackexchange.com/q/62890/15315">improve the connection and overall structure</a>.  I copied the same <code>persistence.xml</code> file over, and added, from Netbeans, EclipseLink from Glassfish for the JPA connection.  </p>
  
  <p>Why isn't the EJB module picking up the persistence.xml file?</p>
  
  <p>tree of the clean project:</p>
  
  <pre><code>LegacyEJB/
  ├── build.xml
  ├── nbproject
  │   ├── ant-deploy.xml
  │   ├── build-impl.xml
  │   ├── genfiles.properties
  │   ├── private
  │   │   └── private.properties
  │   ├── project.properties
  │   └── project.xml
  ├── setup
  │   └── glassfish-resources.xml
  └── src
      ├── conf
      │   ├── MANIFEST.MF
      │   └── persistence.xml
      └── java
          ├── META-INF
          │   └── persistence.xml
          └── net
              └── bounceme
                  └── dur
                      ├── db
                      │   ├── Clients.java
                      │   ├── Criteria.java
                      │   ├── DatabaseConnection.java
                      │   ├── MyProps.java
                      │   ├── User.java
                      │   └── UserRole.java
                      └── legacy
                          └── ejb
                              └── LegacySession.java
  </code></pre>
  
  <p>glassfish stacktrace:</p>
  
  <pre><code>INFO:   visiting unvisited references
  INFO:   EJB5181:Portable JNDI names for EJB LegacySession: [java:global/LegacyEJB/LegacySession!net.bounceme.dur.legacy.LegacySessionRemote, java:global/LegacyEJB/LegacySession]
  INFO:   EJB5182:Glassfish-specific (Non-portable) JNDI names for EJB LegacySession: [net.bounceme.dur.legacy.LegacySessionRemote#net.bounceme.dur.legacy.LegacySessionRemote, net.bounceme.dur.legacy.LegacySessionRemote]
  INFO:   LegacyEJB was successfully deployed in 1,409 milliseconds.
  INFO:   visiting unvisited references
  INFO:   visiting unvisited references
  INFO:   ACDEPL103: Java Web Start services started for the app client LegacyApplication (contextRoot: /LegacyApplication)
  INFO:   LegacyApplication was successfully deployed in 264 milliseconds.
  INFO:   query db
  WARNING:   EJB5184:A system exception occurred during an invocation on EJB LegacySession, method: public java.util.List net.bounceme.dur.legacy.ejb.LegacySession.getAll()
  WARNING:   javax.ejb.EJBException
      at com.sun.ejb.containers.EJBContainerTransactionManager.processSystemException(EJBContainerTransactionManager.java:748)
      at com.sun.ejb.containers.EJBContainerTransactionManager.completeNewTx(EJBContainerTransactionManager.java:698)
      at com.sun.ejb.containers.EJBContainerTransactionManager.postInvokeTx(EJBContainerTransactionManager.java:503)
      at com.sun.ejb.containers.BaseContainer.postInvokeTx(BaseContainer.java:4475)
      at com.sun.ejb.containers.BaseContainer.postInvoke(BaseContainer.java:2009)
      at com.sun.ejb.containers.BaseContainer.postInvoke(BaseContainer.java:1979)
      at com.sun.ejb.containers.EJBObjectInvocationHandler.invoke(EJBObjectInvocationHandler.java:212)
      at com.sun.ejb.containers.EJBObjectInvocationHandlerDelegate.invoke(EJBObjectInvocationHandlerDelegate.java:79)
      at com.sun.proxy.$Proxy368.getAll(Unknown Source)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:606)
      at com.sun.corba.ee.impl.presentation.rmi.ReflectiveTie.dispatchToMethod(ReflectiveTie.java:143)
      at com.sun.corba.ee.impl.presentation.rmi.ReflectiveTie._invoke(ReflectiveTie.java:173)
      at com.sun.corba.ee.impl.protocol.ServerRequestDispatcherImpl.dispatchToServant(ServerRequestDispatcherImpl.java:528)
      at com.sun.corba.ee.impl.protocol.ServerRequestDispatcherImpl.dispatch(ServerRequestDispatcherImpl.java:199)
      at com.sun.corba.ee.impl.protocol.MessageMediatorImpl.handleRequestRequest(MessageMediatorImpl.java:1549)
      at com.sun.corba.ee.impl.protocol.MessageMediatorImpl.handleRequest(MessageMediatorImpl.java:1425)
      at com.sun.corba.ee.impl.protocol.MessageMediatorImpl.handleInput(MessageMediatorImpl.java:930)
      at com.sun.corba.ee.impl.protocol.giopmsgheaders.RequestMessage_1_2.callback(RequestMessage_1_2.java:213)
      at com.sun.corba.ee.impl.protocol.MessageMediatorImpl.handleRequest(MessageMediatorImpl.java:694)
      at com.sun.corba.ee.impl.protocol.MessageMediatorImpl.dispatch(MessageMediatorImpl.java:496)
      at com.sun.corba.ee.impl.protocol.MessageMediatorImpl.doWork(MessageMediatorImpl.java:2222)
      at com.sun.corba.ee.impl.threadpool.ThreadPoolImpl$WorkerThread.performWork(ThreadPoolImpl.java:497)
      at com.sun.corba.ee.impl.threadpool.ThreadPoolImpl$WorkerThread.run(ThreadPoolImpl.java:540)
  Caused by: javax.persistence.PersistenceException: No Persistence provider for EntityManager named LegacyDatabasePU
      at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:85)
      at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:54)
      at net.bounceme.dur.db.DatabaseConnection.connect(DatabaseConnection.java:23)
      at net.bounceme.dur.db.DatabaseConnection.findAll(DatabaseConnection.java:30)
      at net.bounceme.dur.legacy.ejb.LegacySession.getAll(LegacySession.java:19)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:606)
      at org.glassfish.ejb.security.application.EJBSecurityManager.runMethod(EJBSecurityManager.java:1081)
      at org.glassfish.ejb.security.application.EJBSecurityManager.invoke(EJBSecurityManager.java:1153)
      at com.sun.ejb.containers.BaseContainer.invokeBeanMethod(BaseContainer.java:4695)
      at com.sun.ejb.EjbInvocation.invokeBeanMethod(EjbInvocation.java:630)
      at com.sun.ejb.containers.interceptors.AroundInvokeChainImpl.invokeNext(InterceptorManager.java:822)
      at com.sun.ejb.EjbInvocation.proceed(EjbInvocation.java:582)
      at org.jboss.weld.ejb.AbstractEJBRequestScopeActivationInterceptor.aroundInvoke(AbstractEJBRequestScopeActivationInterceptor.java:55)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:606)
      at com.sun.ejb.containers.interceptors.AroundInvokeInterceptor.intercept(InterceptorManager.java:883)
      at com.sun.ejb.containers.interceptors.AroundInvokeChainImpl.invokeNext(InterceptorManager.java:822)
      at com.sun.ejb.EjbInvocation.proceed(EjbInvocation.java:582)
      at com.sun.ejb.containers.interceptors.SystemInterceptorProxy.doCall(SystemInterceptorProxy.java:163)
      at com.sun.ejb.containers.interceptors.SystemInterceptorProxy.aroundInvoke(SystemInterceptorProxy.java:140)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:606)
      at com.sun.ejb.containers.interceptors.AroundInvokeInterceptor.intercept(InterceptorManager.java:883)
      at com.sun.ejb.containers.interceptors.AroundInvokeChainImpl.invokeNext(InterceptorManager.java:822)
      at com.sun.ejb.containers.interceptors.InterceptorManager.intercept(InterceptorManager.java:369)
      at com.sun.ejb.containers.BaseContainer.__intercept(BaseContainer.java:4667)
      at com.sun.ejb.containers.BaseContainer.intercept(BaseContainer.java:4655)
      at com.sun.ejb.containers.EJBObjectInvocationHandler.invoke(EJBObjectInvocationHandler.java:205)
      ... 19 more
  </code></pre>
  
  <p>database connection:</p>
  
  <pre><code>package net.bounceme.dur.db;
  
  import java.sql.Timestamp;
  import java.util.ArrayList;
  import java.util.Date;
  import java.util.List;
  import java.util.logging.Logger;
  import javax.persistence.EntityManager;
  import javax.persistence.EntityManagerFactory;
  import javax.persistence.Persistence;
  import javax.persistence.Query;
  import javax.persistence.criteria.CriteriaBuilder;
  import javax.persistence.criteria.CriteriaQuery;
  import javax.persistence.criteria.Predicate;
  import javax.persistence.criteria.Root;
  
  public enum DatabaseConnection {
  
      INSTANCE;
      private final Logger log = Logger.getLogger(DatabaseConnection.class.getName());
  
      private EntityManager connect() {
          EntityManagerFactory emf = Persistence.createEntityManagerFactory("LegacyDatabasePU");
          EntityManager em = emf.createEntityManager();
          log.fine("" + em.isOpen());
          return em;
      }
  
      public List&lt;Clients&gt; findAll() {
          EntityManager em = connect();
          Query q = em.createQuery("select c from Clients c");
          List&lt;Clients&gt; clients = q.getResultList();
          em.close();
          return clients;
      }
  
      public List&lt;Clients&gt; selectByCriteria(Criteria criteria) {
          log.info(criteria.toString());
          EntityManager em = connect();
          CriteriaBuilder criteriaBuilder = em.getCriteriaBuilder();
          CriteriaQuery&lt;Clients&gt; clientCriteriaQuery = criteriaBuilder.createQuery(Clients.class);
          Root&lt;Clients&gt; clientRoot = clientCriteriaQuery.from(Clients.class);
          clientCriteriaQuery.select(clientRoot);
          List&lt;Predicate&gt; predicates = new ArrayList&lt;&gt;();
          predicates.add(criteriaBuilder.like(clientRoot.get(Clients_.name), "%" + criteria.getName() + "%"));
          predicates.add(criteriaBuilder.like(clientRoot.get(Clients_.phone1), "%" + criteria.getPhone1() + "%"));
          predicates.add(criteriaBuilder.like(clientRoot.get(Clients_.email), "%" + criteria.getEmail() + "%"));
          if (!criteria.getOpener().equalsIgnoreCase("all")) {
              predicates.add(criteriaBuilder.like(clientRoot.get(Clients_.opener), "%" + criteria.getOpener() + "%"));
          }
          if (!criteria.getCloser1().equalsIgnoreCase("all")) {
              predicates.add(criteriaBuilder.like(clientRoot.get(Clients_.closer1), "%" + criteria.getCloser1() + "%"));
          }
          if (!criteria.getStatus().equalsIgnoreCase("all")) {
              predicates.add(criteriaBuilder.like(clientRoot.get(Clients_.status), "%" + criteria.getStatus() + "%"));
          }
          clientCriteriaQuery.where(predicates.toArray(new Predicate[0]));
          List&lt;Clients&gt; clients = em.createQuery(clientCriteriaQuery).getResultList();
          em.close();
          return clients;
      }
  
      public Clients findById(int id) {
          EntityManager em = connect();
          Clients client = em.find(Clients.class, id);
          em.close();
          return client;
      }
  
      public void send(int id) {
          EntityManager em = connect();
          Clients c = em.find(Clients.class, id);
          java.util.Date date = new java.util.Date();
          Timestamp t = new Timestamp(date.getTime());
          em.getTransaction().begin();
          c.setDateUpdated(t.toString());
          em.getTransaction().commit();
          em.close();
      }
  
      private Timestamp stamp() {
          Date d = new Date();
          return new Timestamp(d.getTime());
      }
  
      public int persistClient(Clients client) {
          EntityManager em = connect();
          client.setDateCreated(stamp().toString());
          em.getTransaction().begin();
          em.persist(client);
          em.getTransaction().commit();
          log.fine(client.getTrim());
          em.close();
          return client.getId();
      }
  
      public int update(Clients newClient) {
          EntityManager em = connect();
          Clients oldClient = em.find(Clients.class, newClient.getId());
          em.getTransaction().begin();
          oldClient.setAddress(newClient.getAddress());
          oldClient.setCity(newClient.getCity());
      //omitted for brevity
          oldClient.setVerifier(newClient.getVerifier());
          oldClient.setYear(newClient.getYear());
          em.getTransaction().commit();
          em.close();
          return newClient.getId();
      }
  }
  </code></pre>
  
  <p>persistence:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;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"&gt;
    &lt;persistence-unit name="LegacyDatabasePU" transaction-type="RESOURCE_LOCAL"&gt;
      &lt;provider&gt;org.eclipse.persistence.jpa.PersistenceProvider&lt;/provider&gt;
      &lt;class&gt;legacy.database.Clients&lt;/class&gt;
      &lt;properties&gt;
        &lt;property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/legacy?zeroDateTimeBehavior=convertToNull"/&gt;
        &lt;property name="javax.persistence.jdbc.password" value="password"/&gt;
        &lt;property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"/&gt;
        &lt;property name="javax.persistence.jdbc.user" value="jdbc"/&gt;
      &lt;/properties&gt;
    &lt;/persistence-unit&gt;
  &lt;/persistence&gt;
  </code></pre>
  
  <p>project.properties for the JAR's on the classpath:</p>
  
  <pre><code>annotation.processing.enabled=true
  annotation.processing.enabled.in.editor=true
  annotation.processing.processor.options=-Aeclipselink.canonicalmodel.use_static_factory=false
  annotation.processing.processors.list=
  annotation.processing.run.all.processors=true
  annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output
  build.classes.dir=${build.dir}/classes
  build.classes.excludes=**/*.java,**/*.form,**/.nbattrs
  build.dir=build
  build.ear.classes.dir=${build.dir}/classes
  build.generated.dir=${build.dir}/generated
  build.generated.sources.dir=${build.dir}/generated-sources
  build.test.classes.dir=${build.dir}/test/classes
  build.test.results.dir=${build.dir}/test/results
  debug.classpath=${javac.classpath}:${build.classes.dir}
  debug.test.classpath=\
      ${run.test.classpath}
  dist.dir=dist
  dist.ear.jar=${dist.dir}/${jar.name}
  dist.jar=${dist.dir}/${jar.name}
  dist.javadoc.dir=${dist.dir}/javadoc
  endorsed.classpath=\
      ${libs.javaee-endorsed-api-6.0.classpath}
  excludes=
  includes=**
  j2ee.compile.on.save=false
  j2ee.deploy.on.save=false
  j2ee.platform=1.7
  j2ee.platform.classpath=${j2ee.server.middleware}/mq/lib/jaxm-api.jar:${j2ee.server.home}/modules/endorsed/javax.annotation-api.jar:${j2ee.server.home}/modules/endorsed/webservices-api-osgi.jar:${j2ee.server.home}/modules/endorsed/jaxb-api-osgi.jar:${j2ee.server.home}/modules/javax.websocket-api.jar:${j2ee.server.home}/modules/javax.ws.rs-api.jar:${j2ee.server.home}/modules/bean-validator.jar:${j2ee.server.home}/modules/webservices-osgi.jar:${j2ee.server.home}/modules/javax.xml.registry-api.jar:${j2ee.server.home}/modules/javax.enterprise.concurrent.jar:${j2ee.server.home}/modules/javax.transaction-api.jar:${j2ee.server.home}/modules/javax.enterprise.deploy-api.jar:${j2ee.server.home}/modules/javax.servlet.jsp-api.jar:${j2ee.server.home}/modules/javax.management.j2ee-api.jar:${j2ee.server.home}/modules/javax.servlet.jsp.jstl-api.jar:${j2ee.server.home}/modules/weld-osgi-bundle.jar:${j2ee.server.home}/modules/javax.interceptor-api.jar:${j2ee.server.home}/modules/javax.json.jar:${j2ee.server.home}/modules/javax.servlet.jsp.jstl.jar:${j2ee.server.home}/modules/javax.ejb-api.jar:${j2ee.server.home}/modules/javax.resource-api.jar:${j2ee.server.home}/modules/javax.servlet-api.jar:${j2ee.server.home}/modules/javax.servlet.jsp.jar:${j2ee.server.home}/modules/jaxb-osgi.jar:${j2ee.server.home}/modules/javax.inject.jar:${j2ee.server.home}/modules/javax.security.jacc-api.jar:${j2ee.server.home}/modules/javax.batch-api.jar:${j2ee.server.home}/modules/javax.xml.rpc-api.jar:${j2ee.server.home}/modules/javax.jms-api.jar:${j2ee.server.home}/modules/javax.enterprise.concurrent-api.jar:${j2ee.server.home}/modules/javax.faces.jar:${j2ee.server.home}/modules/javax.persistence.jar:${j2ee.server.home}/modules/javax.security.auth.message-api.jar:${j2ee.server.home}/modules/javax.mail.jar:${j2ee.server.home}/modules/javax.el.jar
  j2ee.platform.embeddableejb.classpath=${j2ee.server.home}/lib/embedded/glassfish-embedded-static-shell.jar
  j2ee.platform.wscompile.classpath=${j2ee.server.home}/modules/webservices-osgi.jar
  j2ee.platform.wsgen.classpath=${j2ee.server.home}/modules/webservices-osgi.jar:${j2ee.server.home}/modules/endorsed/webservices-api-osgi.jar:${j2ee.server.home}/modules/jaxb-osgi.jar:${j2ee.server.home}/modules/endorsed/jaxb-api-osgi.jar
  j2ee.platform.wsimport.classpath=${j2ee.server.home}/modules/webservices-osgi.jar:${j2ee.server.home}/modules/endorsed/webservices-api-osgi.jar:${j2ee.server.home}/modules/jaxb-osgi.jar:${j2ee.server.home}/modules/endorsed/jaxb-api-osgi.jar
  j2ee.platform.wsit.classpath=
  j2ee.server.type=gfv3ee6
  jar.compress=false
  jar.name=LegacyEJB.jar
  jars.in.ejbjar=false
  javac.classpath=\
      ${reference.LegacyLibrary.jar}:\
      ${libs.EclipseLink-GlassFish-v3.classpath}
  javac.debug=true
  javac.deprecation=false
  javac.processorpath=\
      ${javac.classpath}:\
      ${libs.eclipselink.classpath}:\
      ${libs.eclipselinkmodelgen.classpath}
  javac.source=1.7
  javac.target=1.7
  javac.test.classpath=\
      ${javac.classpath}:\
      ${build.classes.dir}
  javac.test.processorpath=${javac.test.classpath}
  javadoc.additionalparam=
  javadoc.author=false
  javadoc.encoding=${source.encoding}
  javadoc.noindex=false
  javadoc.nonavbar=false
  javadoc.notree=false
  javadoc.preview=true
  javadoc.private=false
  javadoc.splitindex=true
  javadoc.use=true
  javadoc.version=false
  javadoc.windowtitle=
  meta.inf=${source.root}/conf
  meta.inf.excludes=sun-cmp-mappings.xml
  platform.active=default_platform
  project.LegacyLibrary=../LegacyLibrary
  reference.LegacyLibrary.jar=${project.LegacyLibrary}/dist/LegacyLibrary.jar
  resource.dir=setup
  run.test.classpath=\
      ${javac.test.classpath}:\
      ${build.test.classes.dir}
  # Space-separated list of JVM arguments used when running a class with a main method or a unit test
  # (you may also define separate properties like run-sys-prop.name=value instead of -Dname=value):
  runmain.jvmargs=
  source.encoding=UTF-8
  source.root=src
  src.dir=${source.root}/java
  test.src.dir=test
  </code></pre>