title: Not able to persist to sql server database using persistence.xml
body: <p>I am new to java. I am trying to connect my application to SQL server database on my machine but getting following error:    </p>
  
  <pre><code>javax.persistence.PersistenceException:No Persistence provider for EntityManager named Sub:     The following providers:
  oracle.toplink.essentials.ejb.cmp3.EntityManagerFactoryProvider
  oracle.toplink.essentials.PersistenceProvider
  Returned null to createEntityManagerFactory.
  </code></pre>
  
  <p>My persistence.xml is:</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="Application"&gt;
       &lt;provider&gt;
          oracle.toplink.essentials.PersistenceProvider
      &lt;/provider&gt;
  
      &lt;class&gt;com.application.entity.ProductEntity&lt;/class&gt;
  
      &lt;properties&gt;
          &lt;property name="toplink.jdbc.url"value="jdbc:sqlserver://localhost:1433;databaseName=Application"/&gt;
          &lt;property name="toplink.jdbc.user" value="sa"/&gt;
          &lt;property name="toplink.jdbc.password" value="Infosys1"/&gt;
          &lt;property name="toplink.jdbc.driver" value="com.microsoft.sqlserver.jdbc.SQLServerDriver"/&gt;
      &lt;/properties&gt;
  
  
  
  &lt;/persistence-unit&gt;
  </code></pre>
  
  <p></p>
  
  <p>My service class is:</p>
  
  <pre><code>package com.application.service;
  
      import javax.persistence.EntityManager;
       import javax.persistence.EntityManagerFactory;
      import javax.persistence.EntityTransaction;
      import javax.persistence.Persistence;
  
      import com.application.entity.ProductEntity;
      import com.application.to.productTo;
  
     public class ProductService 
       {
  
  public int addProduct(productTo to)
  {
      EntityManager em = null;
      ProductEntity product = new ProductEntity();
      try {
      EntityManagerFactory emf = Persistence.createEntityManagerFactory("Sub");
  
          em = emf.createEntityManager();
          EntityTransaction et = em.getTransaction();
          et.begin();
  
          // Persist Product
  
          product.setProductName(to.getProductName());
          product.setBasePrice(to.getBasePrice());
          product.setSellingPrice(to.getSellingPrice());
          product.setQuantity(to.getQuantity());
          product.setCompany(to.getCompany());
  
          em.persist(product);
          et.commit();
  
      } 
      catch (Exception e)
      {
          // TODO Auto-generated catch block
          e.printStackTrace();
      }
      finally 
      {
          if (em != null)
          {
              em.close();
          }
      }
      return product.getProductId();
  
  
      }
       }
  </code></pre>
  
  <p>I have included below jars in java build path and also in lib folder in webcontent:</p>
  
  <ol>
  <li>sqljdbc4-2.0.jar</li>
  <li>toplink-essentials-agent.jar</li>
  <li>toplink-essentials.jar</li>
  </ol>
  
  <p>My persistence.xml path is \Application\src\META-INF\persistence.xml</p>
  
  <p>Kindly help me out. Thanks in advance.</p>