Hi i am new to JPA,
m trying to make a simple jpa application.
My persistence.xml is as follows
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="1.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_1_0.xsd">
<persistence-unit name="JPATest">
<!--<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider> -->
<class>com.jpatest.tables.EmpTable</class>
<properties>
<property name="eclipselink.jdbc.driver"
value="oracle.jdbc.driver.OracleDriver" />
<property name="eclipselink.jdbc.url"
value="jdbc:oracle:thin:@localhost:1521:XE" />
<property name="eclipselink.jdbc.user" value="kunal" />
<property name="eclipselink.jdbc.password" value="kunal" />
</properties>
</persistence-unit>
</persistence>
JPA class is
package com.jpatest.tables;
import java.io.Serializable;
import javax.persistence.*;
import javax.persistence.EntityManager;
/**
* The persistent class for the EMP_TABLE database table.
*
*/
@Entity
@Table(name="EMP_TABLE")
public class EmpTable implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@Column(name="EMP_ID")
private long empId;
@Column(name="EMP_ADDRESS")
private
String empAddress;
@Column(name="EMP_NAME")
private String empName;
public EmpTable() {
}
public long getEmpId() {
return this.empId;
}
public void setEmpId(long empId) {
this.empId = empId;
}
public String getEmpAddress() {
return this.empAddress;
}
public void setEmpAddress(String empAddress) {
this.empAddress = empAddress;
}
public String getEmpName() {
return this.empName;
}
public void setEmpName(String empName) {
this.empName = empName;
}
}
and main class is
package com.jpatest.tables;
import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import javax.persistence.Query;
public class Main {
/**
* @param args
*/
private static EntityManagerFactory factory;
private static final String PersistanceUnit ="EmpTable";
public static void main(String[] args) {
// TODO Auto-generated method stub
//getting entity managers instance
//creting entity manager factory instance for a particular table type
factory=Persistence.createEntityManagerFactory(PersistanceUnit);
//creting entity mangers instance
EntityManager em = factory.createEntityManager();
// Read the existing entries and write to console
//query to fetch all elements formt the table
Query q = em.createQuery("select t from Todo t");
List<EmpTable> todoList = q.getResultList();
for (EmpTable todo : todoList)
{
System.out.println("...............................");
System.out.println(todo);
System.out.println(todo.getEmpId());
System.out.println(todo.getEmpAddress());
System.out.println(todo.getEmpName());
System.out.println("...............................");
}
System.out.println("Size: " + todoList.size());
// Create new todo
em.getTransaction().begin();
EmpTable todo = new EmpTable();
todo.setEmpId(12);
todo.setEmpAddress("sec22");
todo.setEmpName("Mritunjar");
em.persist(todo);
em.getTransaction().commit();
em.close();
}
}
when i am executing this program i am getting error
Exception in
thread "main" javax.persistence.PersistenceException: No Persistence provider for EntityManager named EmpTable
at javax.persistence.Persistence.createEntityManagerFactory(Unknown Source)
at javax.persistence.Persistence.createEntityManagerFactory(Unknown Source)
at com.jpatest.tables.Main.main(Main.java:23)
the location of persistence.xml is META-INF directory
Please help me out of this situation..