Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Eclipse - How to fix error "No persistence.xml file found in project" JPA issue

Error "No persistence.xml file found in project" in Eclipse.

Aim: Create a new project GWT+App engine+Maven

Steps to create this:

  1. Google eclipse plugin: select "New Web Application Project".
  2. set the name etc.
  3. right-click on the project > Configure > Convert to Maven...
  4. Fix jdoconfig.xml file: xsi has the wrong value. see Validating jdoconfig with incorrect url

Then I get the above error.

The file exists at scr/META-INF/persistence.xml and also war/WEB-INF/classes/META-INF/persistence.xml But is not being found.

Notes: I installed plugins m2e, m2e-wtp and google eclipse plugin

like image 945
eddyparkinson Avatar asked Jul 17 '13 09:07

eddyparkinson


People also ask

Is persistence xml required for JPA?

xml configuration. You can use JPA with a very short, basic configuration. You only need a persistence element as the root element and a persistence-unit element with a name attribute.

What is persistence xml in JPA?

The persistence. xml file is a standard configuration file in JPA. It has to be included in the META-INF directory inside the JAR file that contains the entity beans. The persistence.

Where is the persistence XML file?

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.

What is the purpose of the persistence XML file?

The persistence. xml configuration file is used to configure a given JPA Persistence Unit. The Persistence Unit defines all the metadata required to bootstrap an EntityManagerFactory , like entity mappings, data source, and transaction settings, as well as JPA provider configuration properties.


1 Answers

If you are using eclipse. Try right clicking the Project File -> Build Path -> Configure Build Path

Step 1: Add the folder META-INF to the build path

Step 2: Right click the Project File -> Maven -> Update Project

like image 59
Gerard Downes Avatar answered Oct 22 '22 19:10

Gerard Downes