title: No Persistence provider for EntityManager named
body: <p>I got the error "No Persistence provider for EntityManager named projectPersistence
      org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:288)
  " while I'm running my project on the server. Here's my configuration files:</p>
  
  <p>persistence.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;persistence:persistence version="1.0"
      xmlns:persistence="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_1_0.xsd "&gt;
      &lt;persistence:persistence-unit name="projectPersistence"
          transaction-type="RESOURCE_LOCAL"&gt;
          &lt;persistence:provider&gt;org.hibernate.ejb.HibernatePersistence&lt;/persistence:provider&gt;
          &lt;persistence:mapping-file&gt;orm.xml&lt;/persistence:mapping-file&gt;
          &lt;persistence:class&gt;it.test.home.entity.User&lt;/persistence:class&gt;
          &lt;persistence:properties&gt;
              &lt;persistence:property name="hibernate.connection.driver_class"
                  value="com.mysql.jdbc.Driver" /&gt;
              &lt;persistence:property name="hibernate.connection.password"
                  value="root" /&gt;
              &lt;persistence:property name="hibernate.connection.url"
                  value="jdbc:mysql://localhost:3306/hibernate_db" /&gt;
              &lt;persistence:property name="hibernate.connection.username"
                  value="root" /&gt;
              &lt;persistence:property name="hibernate.dialect"
                  value="org.hibernate.dialect.MySQLDialect" /&gt;
  
          &lt;/persistence:properties&gt;
  
      &lt;/persistence:persistence-unit&gt;
  
  &lt;/persistence:persistence&gt;
  </code></pre>
  
  <p>UserDaoImpl.java</p>
  
  <pre><code>package it.test.home.dao;
  // Generated 4-mar-2012 19.36.54 by Hibernate Tools 3.4.0.CR1
  
  
  import it.test.home.entity.User;
  
  import javax.ejb.Stateless;
  import javax.persistence.EntityManager;
  import javax.persistence.PersistenceContext;
  import org.apache.commons.logging.Log;
  import org.apache.commons.logging.LogFactory;
  
  /**
   * Home object for domain model class UserTable.
   * @see it.test.home.entity.User
   * @author Hibernate Tools
   */
  @Stateless
  public class UserDaoImpl implements UserDao {
  
      private static final Log log = LogFactory.getLog(UserDaoImpl.class);
  
      @PersistenceContext(unitName="projectPersistence")
      private EntityManager entityManager;
  
      @Override
      public void persist(User transientInstance) {
          log.debug("persisting UserTable instance");
          try {
              entityManager.persist(transientInstance);
              log.debug("persist successful");
          }
          catch (RuntimeException re) {
              log.error("persist failed", re);
              throw re;
          }
      }
  
      @Override
      public void remove(User persistentInstance) {
          log.debug("removing UserTable instance");
          try {
              entityManager.remove(persistentInstance);
              log.debug("remove successful");
          }
          catch (RuntimeException re) {
              log.error("remove failed", re);
              throw re;
          }
      }
  
      @Override
      public User merge(User detachedInstance) {
          log.debug("merging UserTable instance");
          try {
              User result = entityManager.merge(detachedInstance);
              log.debug("merge successful");
              return result;
          }
          catch (RuntimeException re) {
              log.error("merge failed", re);
              throw re;
          }
      }
  
      @Override
      public User findById( String id) {
          log.debug("getting UserTable instance with id: " + id);
          try {
              User instance = entityManager.find(User.class, id);
              log.debug("get successful");
              return instance;
          }
          catch (RuntimeException re) {
              log.error("get failed", re);
              throw re;
          }
      }
  }
  </code></pre>
  
  <p>projectPersistence-dao.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;beans xmlns="http://www.springframework.org/schema/beans"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
      xmlns:tx="http://www.springframework.org/schema/tx"
      xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
          http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
          http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd"&gt;
  
      &lt;bean
          class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" /&gt;
  
      &lt;bean class="org.springframework.orm.jpa.LocalEntityManagerFactoryBean"
          id="entityManagerFactory"&gt;
          &lt;property name="persistenceUnitName" value="projectPersistence" /&gt;
      &lt;/bean&gt;
      &lt;bean class="org.springframework.orm.jpa.JpaTransactionManager"
          id="transactionManager"&gt;
          &lt;property name="entityManagerFactory" ref="entityManagerFactory" /&gt;
      &lt;/bean&gt;
      &lt;bean autowire="byName" class="it.test.home.dao.UserDaoImpl" id="userDao"&gt;
          &lt;property name="entityManagerFactory" ref="entityManagerFactory" /&gt;
      &lt;/bean&gt;
      &lt;context:component-scan base-package="it.test.home.entity" /&gt;
      &lt;tx:annotation-driven /&gt;
  
  
  
  &lt;/beans&gt;
  </code></pre>
  
  <p>projectPersistence-enterprise.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;beans xmlns="http://www.springframework.org/schema/beans"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop"
      xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx"
      xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
          http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
          http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
          http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd"&gt;
  
      &lt;import resource="projectPersistence-dao.xml" /&gt;
      &lt;context:annotation-config /&gt;
      &lt;tx:annotation-driven /&gt;
  
  
  &lt;/beans&gt;
  </code></pre>
  
  <p>beanRefContext.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;beans xmlns="http://www.springframework.org/schema/beans"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"&gt;
  
      &lt;bean
          class="org.springframework.context.support.ClassPathXmlApplicationContext"&gt;
          &lt;constructor-arg value="classpath*:projectPersistence-enterprise.xml" /&gt;
      &lt;/bean&gt;
  &lt;/beans&gt;
  </code></pre>
  
  <p>servlet-context.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;beans:beans xmlns="http://www.springframework.org/schema/mvc"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:beans="http://www.springframework.org/schema/beans"
      xmlns:context="http://www.springframework.org/schema/context"
      xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
          http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
          http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd"&gt;
  
      &lt;!-- DispatcherServlet Context: defines this servlet's request-processing 
          infrastructure --&gt;
  
      &lt;!-- Enables the Spring MVC @Controller programming model --&gt;
      &lt;annotation-driven /&gt;
  
      &lt;!-- Handles HTTP GET requests for /resources/** by efficiently serving 
          up static resources in the ${webappRoot}/resources directory --&gt;
      &lt;resources mapping="/resources/**" location="/resources/" /&gt;
  
      &lt;!-- Resolves views selected for rendering by @Controllers to .jsp resources 
          in the /WEB-INF/views directory --&gt;
      &lt;beans:bean
          class="org.springframework.web.servlet.view.InternalResourceViewResolver"&gt;
          &lt;beans:property name="prefix" value="/WEB-INF/views/" /&gt;
          &lt;beans:property name="suffix" value=".jsp" /&gt;
      &lt;/beans:bean&gt;
  
      &lt;beans:import resource="classpath*:beanRefContext.xml"/&gt;
  
      &lt;context:component-scan base-package="it.test.home" /&gt;
  
  
  
  &lt;/beans:beans&gt;
  </code></pre>
  
  <p>and, UserServiceImpl.java</p>
  
  <pre><code>package it.test.home.service;
  
  import javax.ejb.Stateless;
  import javax.interceptor.Interceptors;
  
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.ejb.interceptor.SpringBeanAutowiringInterceptor;
  import org.springframework.stereotype.Service;
  
  import it.test.home.dao.UserDao;
  import it.test.home.entity.User;
  
  @Service("userService")
  @Stateless(mappedName="UserService", name="UserService")
  @Interceptors(SpringBeanAutowiringInterceptor.class)
  public class UserServiceImpl implements UserService {
  
      @Autowired
      private UserDao userDao;
  
      @Override
      public void persist(User transientInstance) {
          userDao.persist(transientInstance);
  
      }
  
      @Override
      public void remove(User persistentInstance) {
          userDao.remove(persistentInstance);
  
      }
  
      @Override
      public User merge(User detachedInstance) {
          return userDao.merge(detachedInstance);
      }
  
      @Override
      public User findById(String id) {
          return userDao.findById(id);
      }
  
  }
  </code></pre>
  
  <p>This is the log of my console:</p>
  
  <pre><code>ERROR: org.springframework.web.servlet.DispatcherServlet - Context initialization failed
  org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.context.support.ClassPathXmlApplicationContext#0' defined in URL [file:/C:/Users/Giuseppe/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp2/wtpwebapps/RESTService4.0/WEB-INF/classes/beanRefContext.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.springframework.context.support.ClassPathXmlApplicationContext]: Constructor threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in URL [file:/C:/Users/Giuseppe/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp2/wtpwebapps/RESTService4.0/WEB-INF/classes/projectPersistence-dao.xml]: Invocation of init method failed; nested exception is javax.persistence.PersistenceException: No Persistence provider for EntityManager named projectPersistence
      at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:288)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1035)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:939)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:485)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
      at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294)
      at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225)
      at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291)
      at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
      at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:585)
      at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:913)
      at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:464)
      at org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:631)
      at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:588)
      at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:645)
      at org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:508)
      at org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:449)
      at org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:133)
      at javax.servlet.GenericServlet.init(GenericServlet.java:160)
      at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1266)
      at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1185)
      at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1080)
      at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:5015)
      at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5302)
      at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
      at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1568)
      at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1558)
      at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
      at java.util.concurrent.FutureTask.run(FutureTask.java:138)
      at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
      at java.lang.Thread.run(Thread.java:662)
  </code></pre>
  
  <p>I also included hibernate-core and hibernate-entitymanager in Maven dependencies and the persistence.xml is included in the classpath by default.</p>
  
  <p>Any help would be appreciated. Thanks.</p>