Eclipse does not recognize content of persistence.xml
JavaEclipseOrmJpaM2eclipseJava Problem Overview
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
Java Solutions
Solution 1 - Java
I fixed the problem the following way (I'm using RAD v8.5.1):
- Windows --> Preferences --> Validation
- Scroll down to "JPA Validator" and click on the Ellipses under Settings.
- Click on the "Add Include Group..." button.
- Click on the new Include Group that appeared to highlight it.
- Click on the "Add Rule..." button.
- A dialog menu pops up. Click the "Folder or file name" radio button and click on "Next".
- 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.
- Click on "Finish".
- Click on "OK". This will prompt a full build.
- The error will go away.
Solution 2 - Java
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 - Java
<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 - Java
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 - Java
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"
Solution 6 - Java
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.
Solution 7 - Java
The bug has reappeared for certain Indigo (3.7) versions. See here: https://bugs.eclipse.org/bugs/show_bug.cgi?id=357810
Right-click project -> Maven -> Update Project Configuration...
This might destroy certain buildpath entries and/or the deployment assembly, very annoying, so only do this when changing Maven deps.
To workaround the persistence.xml message until the patch is released, you need to clean the project on many operations as even setting the error level to "ignore" doesn't work. This is a complete bummer.
Solution 8 - Java
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"
Solution 9 - Java
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.
Solution 10 - Java
No 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.
Solution 11 - Java
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.
Solution 12 - Java
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.
Solution 13 - Java
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.
Solution 14 - Java
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.
Solution 15 - Java
Whereabouts in your project structure is the file located?
For ref, I have mine in maven-module-name/src/main/resources/META-INF/
Solution 16 - Java
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).
Solution 17 - Java
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.
Solution 18 - Java
I came accross the same problem. Goto project properties -> Java build path -> source , remove **/*.java excluded attribute of src/main/resources source. Then add META-INF/persistence.xml. Then restart eclipse. You should persistence.xml under JPA Content in Project explorer. After that revert your changes.
Well, what I suggest seem stupid, but magically it works. By the way my eclipse version is 3.6.
Solution 19 - Java
The problem has been fixed in Indigo (released in June 2011), see https://bugs.eclipse.org/bugs/show_bug.cgi?id=251323#c24 and https://issues.sonatype.org/browse/MECLIPSEWTP-11.
The "persistence.xml file does not have recognized content." error might still appear, randomly, on project import or Workspace startup, but it can be fixed with a project clean or maven project update. This will be fixed in Dali in SR2.
Solution 20 - Java
I had the same problem, to make it go away I had to make sure this line was the very first line at the top of the file (with no leading empty lines or spaces):
<?xml version="1.0" encoding="UTF-8"?>
Solution 21 - Java
I had the same error, but solved it in a different way.
The thing is that META-INF must be considered a source folder, and as it was under /ejbModule (mine is a EJB project) I assumed it was on the build path. And it wasn't. Actually it was on "exclude" list on build path. So, all I did was right-click the META-INF folder on Project Explorer view and selected INCLUDE on Build Path menu. Then I asked Eclipse to clean the project and everything was right again.
Best Regards.
Solution 22 - Java
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.
Solution 23 - Java
In my case it was the Maven plugin which has a bug that sets "Exclude" to . in the Build path for your resources folder. Removing . solved the issue for me
Solution 24 - Java
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.
Solution 25 - Java
just solved the issue by doing this:
- 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"
-
i added
<?xml version="1.0" encoding="UTF-8"?>
at the top. -
i clean build the project. error's gone.
-
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"
-
i clean build the project. error's not there.
-
i deleted
<?xml version="1.0" encoding="UTF-8"?>
at the top. -
i clean build the project. error's still not there.
hope this helps someone in the future.
Solution 26 - Java
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.
Solution 27 - Java
For me it worked once I have cleared all messages from Markers tab in eclipse
Solution 28 - Java
Add your JPA Version to the Project Facets to remove this error.
In my case i have used JPA 2.2 but in Project Facets JPA 1.0 was specified. After fixing this, the error disappeared.