Eclipse does not recognize content of persistence.xml

前端 未结 27 1732
野趣味
野趣味 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:10

    I got it fixed by dragging META-INF folder to src/main/resources and drag it back to src/test/resources. Thats all it took for me to fix the issue. I tried above given all steps but none of those seem to be working for me and finally this one done the trick.

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

    Turning this error into a warning may make the problem go away, but it will not fix the underlying problem with the Eclipse Dali plugin. It will also mean the extremely useful JPA Structure and JPA Details views will not work.

    The link offered by OP and the approach of most of the answers here are actually meant to get around a different problem wherein Maven wants to filter the persistence.xml file and thus tells Eclipse to ignore it. A viable work-around for that problem is explained here and involves removing the exclused: '**' from the src/main/resources entry in the classpath in the project properties.

    Back to the OP's original question, I had this EXACT same error message (which in and off itself tells you that the persistence.xml file has been located). For me the solution was to change the persistence XML element from this:

    <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_1_0.xsd"
        version="1.0">
    

    to this:

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

    Once changed, the error went away and Dali instantly came alive and now everything Just Works. Hope this helps somebody someday.

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

    This problems occurs if you

    • Convert a JPA project to a Maven project or
    • Add the JPA facet to a Maven project.

    The solution is

    • Select Windows > Preferences > Validation
    • Disable the JPA Validator for both Manual validation and Build validation

    After changing these settings,then clean your project.

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