I have a problem with my dynamic web application. I just started learning JavaEE 6, and now I'm standing on JPA. I set up my application, added libraries, but I still get this annoying information: there is no Persistence provider for EntityManager named X. I'm trying to get an answer on the Internet, but nothing helps me.
This is my persistance.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="PierwszaAplikacja" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<class>devcastzone.javaee.Uzytkownik</class>
<properties>
<property name="hibernate.connection.username" value="root"/>
<property name="hibernate.connection.password" value=""/>
<property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver"/>
<property name="hibernate.connection.url" value="jdbc:mysql://localhost/szkolenie_javaee?characterEncoding=utf8"/>
<property name="hibernate.cache.provider_class" value="org.hibernate.cache.NoCacheProvider"/>
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/>
</properties>
</persistence-unit>
This is my Uzytkownik.java class:
import java.io.Serializable;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
@Entity
@Table(name="uzytkownik")
public class Uzytkownik implements Serializable {
private static final long serialVersionUID = -3299291830280417103L;
@Id
private int id;
private String imie;
private String nazwisko;
}
And my creator EntityManagerFactory in the servlet:
protected void doGet(HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException
{
res.setContentType("text/plain;charset=utf-8");
res.getWriter().println("Cos tam cos tam");
EntityManagerFactory emf = Persistence.createEntityManagerFactory("PierwszaAplikacja");
EntityManager em = emf.createEntityManager();
Uzytkownik u = em.find(Uzytkownik.class, 1);
res.getWriter().println(u.getImie() + " " + u.getNazwisko() + "\n");
em.close();
emf.close();
}
Of course, I have my persistence.xml in the root in META-INF. Maybe someone can help me in this matter?
source
share