I'm trying to develop a Java EE web application using JPA to manage the DB.
When I try to retrieve the rows from my database I've an error :
"No Persistence provider for EntityManager named test"
The code of my function using JPA is :
EntityManagerFactory emf = Persistence.createEntityManagerFactory("test");
EntityManager em =emf.createEntityManager();
EntityTransaction tx = em.getTransaction();
try {
tx.begin();
@SuppressWarnings("unchecked")
List<InputHStock> iph = em.createQuery("from Student").getResultList();
for (Iterator<InputHStock> iterator = iph.iterator(); iterator.hasNext();) {
InputHStock student = (InputHStock) iterator.next();
System.out.println(student.getLocationCode());
}
tx.commit();
} catch (Exception e) {
tx.rollback();
}
}
My persistence.xml file :
<?xml version="1.0" encoding="UTF-8"?>
<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">
<persistence-unit name="test">
<class>application.InputHStock</class>
<properties>
<property name="javax.persistence.jdbc.driver" value="oracle.jdbc.driver.OracleDriver" />
<property name="javax.persistence.jdbc.url" value="jdbc:oracle:thin:@localhost:1521:xe" />
<property name="javax.persistence.jdbc.user" value="testSQL" />
<property name="javax.persistence.jdbc.password" value="testpwd1" />
<property name="eclipselink.ddl-generation" value="create-tables" />
<property name="eclipselink.ddl-generation.output-mode" value="database" />
</properties>
</persistence-unit>
</persistence>
Here is my arborescence in eclipse :
I've also tried using the Eclipse tool to include JPA but without success.
Note that the connection to the database is working as I can retrieve my data when using directly JDBC.