views:

295

answers:

4

Im getting the following error in eclipse:

The persistence.xml file does not have recognized content.

My persistence.xml file works great in my application but eclipse keeps giving me this error. I got this after moving the file and updating my project configuration with m2eclipse. I did not change the file itself. Anyone knows how to solve this?

persistence.xml:

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.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_2_0.xsd"&gt;
    <persistence-unit name="localDB" transaction-type="RESOURCE_LOCAL">

        <provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
        <class>package.Users</class>
        <properties>
            <!-- enable warnings for debugging -->
            <property name="openjpa.Log" value="DefaultLevel=TRACE, Runtime=INFO, Tool=INFO, SQL=TRACE"/>
            <!-- connection properties -->
            <property name="openjpa.ConnectionURL" value="jdbc:mysql://localhost/test"/>
            <property name="openjpa.ConnectionDriverName" value="com.mysql.jdbc.Driver"/>
            <property name="openjpa.ConnectionUserName" value="root"/>
            <property name="openjpa.ConnectionPassword" value=""/>

        </properties>
    </persistence-unit>
</persistence>

Update

Looks like a bug in m2eclipse in combination with jpa.

https://bugs.eclipse.org/bugs/show_bug.cgi?id=251323

Temporarily solved by setting the option to show it as a warning instead of an error

A: 

Whereabouts in your project structure is the file located?

For ref, I have mine in maven-module-name/src/main/resources/META-INF/

Qwerky
mine is in the same location (src/main/resources/META-INF/). I eclipse can find the file but it gives the error message on the file.
Mark Baijens
A: 

Hard to say since hard to reproduce (your persistence.xml is perfectly valid) but maybe try to:

  • Clean the project (both an "Project > Clean" and a Maven clean)
  • Force Eclipse to validate the XML file again (right-click, and select Validate XML file).
Pascal Thivent
That does not work unfortunately
Mark Baijens
@Mark Sorry for that. Another idea: try do delete the project (from eclipse only) and to reimport it.
Pascal Thivent
Looks like it's a bug between m2eclipse and eclipse jpa facet. I set it to a warning as a quick fix for now.
Mark Baijens
A: 

I've had the same problem on a few occasions and what worked for me was to copy the contents of the file, delete it and create a new persistence.xml file and paste the contents back in.

willcodejavaforfood
Doesn't work for me unfortunately
Mark Baijens
@Mark - oh bummer :(
willcodejavaforfood
+1  A: 

I figured out what the problem is here.... the JPA Facet is assuming that the META-INF folder is directly under a source folder. If you are using a Maven project, you likely have something like src/main/resources or src/test/resources. If your persistence.xml is under these folders it will complain. If you create a new source folder (call it "jpa") and create a META-INF/persistence.xml in there, then it will find it successfully. (I also had to do a clean/close/open project)

This is certainly a pain.... and I can see many situations this won't work well.

What is the reason you set the src/main/resource build path to the first place in Order/Export if you still get the error? And a new source folder is no solution for me since i want to keep my current file structure because it's standard for maven. But thanks for pointing out the problem is in the JPA facet. If i'm right the eclipse team still blames m2eclipse :P.
Mark Baijens