Eclipse does not recognize content of persistence.xml

83,610

Solution 1

I fixed the problem the following way (I'm using RAD v8.5.1):

  1. Windows --> Preferences --> Validation
  2. Scroll down to "JPA Validator" and click on the Ellipses under Settings.
  3. Click on the "Add Include Group..." button.
  4. Click on the new Include Group that appeared to highlight it.
  5. Click on the "Add Rule..." button.
  6. A dialog menu pops up. Click the "Folder or file name" radio button and click on "Next".
  7. Click on "Browse Folder..." and navigate to your src directory (in my case, it was "src/main/resources") within your project (my project was a .war in a multi module app) in your workspace.
  8. Click on "Finish".
  9. Click on "OK". This will prompt a full build.
  10. The error will go away.

Solution 2

Had same problem with error

The persistence.xml file does not have recognized content

Fixed by editing file in eclipse, any edit will do. And after saving error got away.

Solution 3

<persistence 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"
version="2.0">

Worked for me!

Solution 4

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.

Solution 5

I had this same problem in Eclipse 3.6 (Helios). The cause was the JPA Facet was set to JPA Version 1.0, however my persistence.xml file was specifying JPA Version 2. So I changed the JPA Facet to version 2.0 and the problem went away. (Project --> Properties --> Project Facets --> "Configuration" drop down --> set this to "Minimal JPA 2.0 configuration"

Share:
83,610
Mark Baijens
Author by

Mark Baijens

Software developer at Quantore. Working with the RAD framework Outsystems and .NET software. Pretty handy with javascript/jQuery aswell.

Updated on July 09, 2022

Comments

  • Mark Baijens
    Mark Baijens almost 2 years

    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">
        <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

    • Neil H
      Neil H almost 13 years
      Please try Dali 3.0.x (part of the Java EE Indigo package). This issue is largely fixed in the Indigo release. There is one remaining issue that may require a project Clean... after project creation/import, but you should no longer need to modify any project metadata to solve the problem, and all Dali functionality should simply work. Please comment on the above mentioned bug if you experience any issues.
    • Wolfgang Fahl
      Wolfgang Fahl over 9 years
      maven project update didn't fix it for me - I assume a clean is part of this. switching off the JPA facet made the error go away.
  • Mark Baijens
    Mark Baijens almost 14 years
    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.
  • Devanshu Mevada
    Devanshu Mevada almost 14 years
    @Mark Sorry for that. Another idea: try do delete the project (from eclipse only) and to reimport it.
  • Mark Baijens
    Mark Baijens almost 14 years
    Looks like it's a bug between m2eclipse and eclipse jpa facet. I set it to a warning as a quick fix for now.
  • jadrake
    jadrake over 13 years
    Based on references here: eclipse.org/forums/… I was able to get this to work by moving the src/main/resources to the first Order/Export in the Build path. I still get an error that persistence.xml is not valid under src/main/resources but this can get ignored I believe under the Java Persistence preferences tab -> Errors/Warnings -> Project -> "Invalid Content (no root node):"
  • Mark Baijens
    Mark Baijens over 13 years
    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
    Mark Baijens over 13 years
    I'm already using version 2.0, so it doesn't work for me unfortunately.
  • Dave
    Dave over 13 years
    Indeed, I changed to 1.0 just to check and Dali still worked. It must have been that saving the file itself trigger Dali in some way. This is all very flaky.
  • J Slick
    J Slick almost 11 years
    Geez, I just came across my own post about this annoying problem, which has now occurred in Eclipse Kepler. Persistence.xml with eclipselink provider was working fine. I added Hibernate tools so I'd have a query editor, but then I removed the Hibernate stuff. Now the stupid thing won't validate Persistence.xml, which was not changed at all. Moreover, it is NOT a Maven project.
  • J Slick
    J Slick almost 11 years
    The "fix" was to ensure that src/META-INF is on build path... although persistence.xml and JPA had been working prior to fooling around with Hibernate tools.
  • alterfox
    alterfox over 10 years
    First I made a minor edit and nothing happened. But then made a larger edit (eventually reverting the changes), and only then the error went away.
  • Stijn de Witt
    Stijn de Witt over 10 years
    Unfortunately, the error comes back just as easy as it went away :(
  • Kevin Bowersox
    Kevin Bowersox over 9 years
    This also worked for me, however I have no idea why since I see many examples without the xml namespace specified
  • Andreas Covidiot
    Andreas Covidiot over 9 years
    It may be worth noting, that I did some major change before, where I renamed the package the *.gwt.xml file was in.
  • Michael Osofsky
    Michael Osofsky over 9 years
    Thanks @Chris, your solution worked for me too but I don't understand why we've used an Include Group if the purpose was to exclude the directory from filtering.
  • Admin
    Admin over 8 years
    Hi Yok, I'm not clear what solution did you provided? Could you please guide ? Thanks, Sayali
  • sbnarra
    sbnarra over 6 years
    eclipse had imported my project and configured it as JPA 1.0. I had to manually update eclipse settings to JPA 2.0 and this resolved the issue for me too