Вопрос

I'm trying execute a vaadin7 application with JPA EclipseLink. I created a folder META-INF on src/ but doesn't work and returns this error bellow:

javax.servlet.ServletException: com.vaadin.server.ServiceException:   javax.persistence.PersistenceException: No Persistence provider for EntityManager named myapp
com.vaadin.server.VaadinServlet.service(VaadinServlet.java:240)
javax.servlet.http.HttpServlet.service(HttpServlet.java:723) 

I added all jars in Build-Path and WEB-INF/lib and my persistences.xml in src/META-INF is bellow.

<?xml version="1.0" encoding="UTF-8"?>
<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"
    version="2.0" 
    xmlns="http://java.sun.com/xml/ns/persistence">

  <persistence-unit name="myapp" transaction-type="RESOURCE_LOCAL">
      <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
      <class>com.example.testejpa.HelloWorld</class>

      <properties>
           <property name="javax.persistence.jdbc.driver" value="com.mysq.jdbc.Driver" />
           <property name="javax.persistence.jdbc.url" value="jdbc:mysql://xxx.xxx.xxx.xxx:3306/mydb" />
           <property name="javax.persistence.jdbc.user" value="user" />
           <property name="javax.persistence.jdbc.password" value="pass" />
           <property name="eclipselink.logging.level" value="FINE"/>  
    </properties>

    </persistence-unit>
</persistence> 

Any idea why this exception ?

Это было полезно?

Решение

The file is named persistence.xml and not persistences.xml as you did.

It has to be placed in the META-INF folder. Make sure that this folder is included in your WEB-INF folder.

From the The Java EE 6 Tutorial:

If you package the persistence unit as a set of classes in a WAR file, persistence.xml should be located in the WAR file’s WEB-INF/classes/META-INF directory.

If you package the persistence unit in a JAR file that will be included in a WAR or EAR file, the JAR file should be located in either

  • The WEB-INF/lib directory of a WAR
  • The EAR file’s library directory

Другие советы

<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>

You have a persistanceProvider

It is looking for a EntityManager Provider. The EntityManager is beeing used to persist data into a database. I guess this might be the problem and you need to add it into your persisteance.xml file.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top