title: "No Persistence provider for EntityManager named manager1" error with JPA 2.0 and Spring 3.1
body: <p>I'm working now on a project using Spring 3.1 and JPA 2.0 and i'm getting an log message error telling me : "<strong>No Persistence provider for EntityManager named manager1</strong>".</p>
  
  <p>Here's my persistence.xml :</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;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"&gt;
  &lt;persistence-unit name="DemoSpringCore" transaction-type="RESOURCE_LOCAL"&gt;
      &lt;provider&gt;org.hibernate.ejb.HibernatePersistence&lt;/provider&gt;
      &lt;class&gt;app.demo.model.Operation&lt;/class&gt;
      &lt;properties&gt;
          &lt;property name="hibernate.connection.url" value="jdbc:mysql://localhost:3309/test"/&gt;
          &lt;property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver"/&gt;
          &lt;property name="hibernate.connection.username" value="root"/&gt;
          &lt;property name="hibernate.connection.password" value="root"/&gt;
          &lt;property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/&gt;
          &lt;property name="hibernate.show_sql" value="true"/&gt;
      &lt;/properties&gt;
  &lt;/persistence-unit&gt;
  </code></pre>
  
  <p></p>
  
  <p>Here's my managed enity "Operation.java" :
      package app.demo.model;</p>
  
  <pre><code>import java.io.Serializable;
  import javax.persistence.Column;
  import javax.persistence.Entity;
  import javax.persistence.GeneratedValue;
  import javax.persistence.GenerationType;
  import javax.persistence.Id;
  import javax.persistence.Table;
  
  @Entity
  @Table(name="operation")
  public class Operation implements Serializable{
  
  private static final long serialVersionUID = 1L;
  
  @Id
  @GeneratedValue(strategy=GenerationType.AUTO)
  private int id;
  
  @Column(name="a",length=9)
  private int a;
  
  @Column(name="b",length=9)
  private int b;
  
  @Column(name="c",length=10)
  private int c;
  
  public int getA() {
      return a;
  }
  public void setA(int a) {
      this.a = a;
  }
  public int getB() {
      return b;
  }
  public void setB(int b) {
      this.b = b;
  }
  public int getC() {
      return c;
  }
  public void setC(int c) {
      this.c = c;
  }
  public int getId() {
      return id;
  }
  public void setId(int id) {
      this.id = id;
  }
  }
  </code></pre>
  
  <p>Here's my java configuration file "AppConfiguration.java" the alternative of "ApplicationContext.xml" in Spring 3.1 :</p>
  
  <pre><code>package app.demo.config;
  
  import java.util.Properties;
  import com.jolbox.bonecp.BoneCPDataSource;
  import javax.annotation.Resource;
  import javax.sql.DataSource;
  import org.springframework.context.annotation.Bean;
  import org.springframework.context.annotation.Configuration;
  import org.springframework.context.annotation.ImportResource;
  import org.springframework.context.annotation.PropertySource;
  import org.springframework.core.env.Environment;
  import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
  import app.demo.dao.OperationDAO;
  import app.demo.dao.OperationDAOImpl;
  import app.demo.service.OperationServiceImpl;
  import app.demo.service.OperationService;
  import org.hibernate.ejb.HibernatePersistence;
  
  @Configuration
  @PropertySource("/META-INF/application.properties")
  public class AppConfiguration {
  
  private static final String PROPERTY_NAME_DATABASE_DRIVER = "db.driver";
  private static final String PROPERTY_NAME_DATABASE_PASSWORD = "db.password";
  private static final String PROPERTY_NAME_DATABASE_URL = "db.url";
  private static final String PROPERTY_NAME_DATABASE_USERNAME = "db.username";
  
  private static final String PROPERTY_NAME_HIBERNATE_DIALECT = "hibernate.dialect";
  private static final String PROPERTY_NAME_HIBERNATE_FORMAT_SQL = "hibernate.format_sql";
  private static final String PROPERTY_NAME_HIBERNATE_SHOW_SQL = "hibernate.show_sql";
  private static final String PROPERTY_NAME_ENTITYMANAGER_PACKAGES_TO_SCAN = "entitymanager.packages.to.scan";
  // private static final String PROPERTY_NAME_HIBERNATE_NAMING_STRATEGY =
  // "hibernate.ejb.naming_strategy";
  
  @Resource
  private Environment environment;
  
  @Bean(name = "operationServiceBean")
  public OperationService operationService() {
      return new OperationServiceImpl();
  }
  
  @Bean(name = "operationDAOBean")
  public OperationDAO operationDAO() {
      return new OperationDAOImpl();
  }
  
  @Bean
  public DataSource dataSource() {
  
      BoneCPDataSource dataSource = new BoneCPDataSource();
  
      dataSource.setDriverClass(environment
              .getRequiredProperty(PROPERTY_NAME_DATABASE_DRIVER));
      dataSource.setJdbcUrl(environment
              .getRequiredProperty(PROPERTY_NAME_DATABASE_URL));
      dataSource.setUsername(environment
              .getRequiredProperty(PROPERTY_NAME_DATABASE_USERNAME));
      dataSource.setPassword(environment
              .getRequiredProperty(PROPERTY_NAME_DATABASE_PASSWORD));
  
      return (DataSource) dataSource;
  }
  
  @Bean
  public LocalContainerEntityManagerFactoryBean entityManagerFactoryBean()
          throws ClassNotFoundException {
      LocalContainerEntityManagerFactoryBean entityManagerFactoryBean = new LocalContainerEntityManagerFactoryBean();
  
      entityManagerFactoryBean
              .setPersistenceProviderClass(HibernatePersistence.class);
  
      entityManagerFactoryBean.setDataSource(dataSource());
  
      Properties jpaProterties = new Properties();
      jpaProterties.put(PROPERTY_NAME_HIBERNATE_DIALECT, environment
              .getRequiredProperty(PROPERTY_NAME_HIBERNATE_DIALECT));
      jpaProterties.put(PROPERTY_NAME_HIBERNATE_FORMAT_SQL, environment
              .getRequiredProperty(PROPERTY_NAME_HIBERNATE_FORMAT_SQL));
      jpaProterties.put(PROPERTY_NAME_HIBERNATE_SHOW_SQL, environment
              .getRequiredProperty(PROPERTY_NAME_HIBERNATE_SHOW_SQL));
      jpaProterties
              .put(PROPERTY_NAME_ENTITYMANAGER_PACKAGES_TO_SCAN,
                      environment
                              .getRequiredProperty(PROPERTY_NAME_ENTITYMANAGER_PACKAGES_TO_SCAN));
      // jpaProterties.put(PROPERTY_NAME_HIBERNATE_NAMING_STRATEGY,
      // environment
      // .getRequiredProperty(PROPERTY_NAME_HIBERNATE_NAMING_STRATEGY));
      entityManagerFactoryBean.setJpaProperties(jpaProterties);
  
      return entityManagerFactoryBean;
  }
  }
  </code></pre>
  
  <p>and finally my "application.properties" where i put datasource connection properties :</p>
  
  <pre><code>db.driver=com.mysql.jdbc.Driver
  db.url=jdbc:mysql://localhost:3309/test
  db.username=root
  db.password=root
  
  hibernate.dialect=org.hibernate.dialect.MySQLDialect
  hibernate.format_sql=true
  hibernate.show_sql=true
  
  entitymanager.packages.to.scan=app.demo.model
  </code></pre>
  
  <p>P.S : I used both methods "appliaction.properties" and also "persistence.xml" each one alone and after both of them in the same time in hope that'll work but nothing happenned !
  Moreover i added the provider attribute in both "AppConfiguration.java" and "persistence.xml" and i verified the existence of all dependencies jar files !</p>
  
  <p>Thanks in advance :)</p>