Eclipse does not recognize content of persistence.xml

前端 未结 27 1731
野趣味
野趣味 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 21:04

    I had src/main/java/META-INF/persistence.xml working fine in Eclipse with embedded Tomcat. Because it was not being copied into the Maven-built WAR, I moved it to src/main/resources/META-INF.

    Now src/main/resources/META-INF/persistence.xml won't validate.

    If rename to xyz_persistence.xml, it validates fine.
    If rename to persistence.xml, it fails to validate.

    When these annoying situations arise, I often find numerous different "solutions" like mine, most of which are not universally applicable.

    So, here's my "solution", which I think it a hack to get around a bug:

    To remove the error "persistence.xml file does not have recognized content" error, disable the JPA Validator:

    • List item Select menu item Project > Properties > Preferences > Validation
    • List item Disable the JPA Validator for both Manual validation and Build validation.

    You might need to clean and rebuild. Your mileage may vary.

    0 讨论(0)
  • 2021-01-30 21:06

    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.

    0 讨论(0)
  • 2021-01-30 21:07

    just solved the issue by doing this:

    1. in schemaLocation, i deleted "h ttp://java.sun.com/xml/ns/persistence/" making it:

    xsi:schemaLocation="http://java.sun.com/xml/ns/persistence persistence_2_0.xsd"

    1. i added <?xml version="1.0" encoding="UTF-8"?> at the top.

    2. i clean build the project. error's gone.

    3. i added the "h ttp://java.sun.com/xml/ns/persistence/" again:

    xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"

    1. i clean build the project. error's not there.

    2. i deleted <?xml version="1.0" encoding="UTF-8"?> at the top.

    3. i clean build the project. error's still not there.

    hope this helps someone in the future.

    0 讨论(0)
  • 2021-01-30 21:09

    I am using eclipse mars and had this same exact error. What I had to do was 1 set the version of jpa for the project facet. right click project -> Properties -> Project Facets Set version of jpa to 2.1 in my case.

    Note: Just configuring the jpa project facet will not remove the error. You also need to configure the platform.

    Next I had to configure the JPA platform. right click project -> Properties -> JPA. Change platoform to be Hibernate 2.1 in my case.

    This problem also manifests itself when you open the persistence.xml with the Persistence XML Editor and you only have a single Source tab at the bottom and not the other tabs for General, Connection, Options, Properties etc.

    0 讨论(0)
  • 2021-01-30 21:10

    Any updates on this? This is still an issue it seems right? If I create a JPA project, convert to Maven project, the error appears and I can't get rid of it with any of the recommended methods.

    Edit

    Ok so after maneuvering some folders around so its in an actual Maven directory format, it still didn't work - but creating a linked folder under src/main/java named META-INF, linked to src/main/resources/META-INF it was resolved.

    Creating a Maven project and adding the JPA facet works also, but only because the JPA facet adds the META-INF and persistence.xml file to src/main/java which I don't think is exactly right.

    0 讨论(0)
  • 2021-01-30 21:10

    enter image description hereNo Need to change andthing in your xml file and no need to add xml in src folder. Put your persistance.xml file in META-INF folder and then put META-INF src/main/resource folder. Try following approach: Right click on project> Java Build path > Source Tab > ProjectName/src/main/resource > set Included(All) and Excluded(None). then clean and build your project. It will work for you. Tried this approach on RAD 7 & 8..5 & Eclipse.

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