Eclipse does not recognize content of persistence.xml

前端 未结 27 1729
野趣味
野趣味 2021-01-30 20:44

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 e

相关标签:
27条回答
  • 2021-01-30 20:44
    <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!

    0 讨论(0)
  • 2021-01-30 20:44

    I got the issue fixed by creating a "symbolic link" in Eclipse. So, my persistence.xml file remains in src/main/resources/META-INF as Maven expects and m2eclipse requires. However, in order to fix the Dali issues, create a new file in src/main/java/META-INF that links to the one in src/main/resources/META-INF. You do this by hitting the "Advanced" options when creating the new file and locating the file using the "Browse..." button. Note that this will not create a physical file in the META-INF folder, however, you need the folder itself in order to create the link.

    Hope that works for you.

    0 讨论(0)
  • 2021-01-30 20:44

    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).
    0 讨论(0)
  • 2021-01-30 20:45

    Ok ... another rather robust solution that worked for me since the top-most ones did not:

    • since I used Mercurial and could go back easily without any notable differences in the current and last versions it worked this way:

    • (committed some important changes rather unrelated to this problem)

    • switching to previous repo version
    • (auto-/refresh/-rebuild ran fine)

    What I recognized was, that the problem may have been due to the fact that the Java Builder did not generate my war/WEB-INF/classes/ files. The following did not work to follow this trail in letting it build my project:

    • disabling/reconfiguring Validators, Builders, Facets (till only the Java Builder/Facet was there)
    • renaming the persistence.xml or editing it in various ways

    which did not help it as if some internal state could not be changed.

    0 讨论(0)
  • 2021-01-30 20:46

    I fixed this by going to Project - Properties - Java Persistence: and then setting the "Source Folder" in the "Canonical metamodel (JPA 2.0)" section to: "src/generated/resources"

    0 讨论(0)
  • 2021-01-30 20:47

    I've had the same problem. My solution: right click on the persistence.xml file -> JPA-Tools -> Synchronize Class List. After that it was resolved.

    0 讨论(0)
提交回复
热议问题