34

For my projects Necessity i regroup all the persistence.xml entries in one core project which i bind as maven dependency wherever i need.

The problem is that the eclipse IDE is always complaining about

No persistence.xml  file found in project

Is there away to keep eclipse quiet about this? Thanks

1

8 Answers 8

67

Thanks to sionnach733 who put me on the right way

enter image description here

4
  • Image no longer available.
    – ffleandro
    Commented Mar 21, 2016 at 14:07
  • 5
    Ignoring problems is generally bad advice. See the other answers.
    – MageWind
    Commented Apr 9, 2017 at 23:40
  • 1
    Ignoring errors is not the same as having a sane project. See my answer below for the correct way to disable the JPA Facet.
    – bakoyaro
    Commented Aug 18, 2017 at 16:24
  • Setting the severity to "Ignore" will make the warning go away in your Problems view, but it doesn't solve the underlying problem. M2E has activated the JPA facet on the project. The unneeded JPA facet will still waste resources (such as observing the project for changes that may affect the persistence unit), so it's NOT a good idea to ignore the problem. See my solution below. You want to disable the facet and tell M2E to not re-configure the JPA facet for that project, which can be done by disabling it globally on the Maven Preferences page, or per-project by setting the property I mention. Commented Oct 31, 2019 at 23:11
17

If this error occurs on a Maven project that does not require the JPA facet, you can tell m2e not to apply the JPA activation (essentially, not to add the JPA facet during project configuration) by setting the following property in the pom.xml of the affected project:

<properties>
    <m2e.jpa.activation>false</m2e.jpa.activation>
</properties>

If you press CTRL-SPACE within an existing <properties> tag, in the pom.xml source, content-assist will provide a shortcut to create the property, so you don't really have to remember the syntax, just that the content assist is there... ;)

After applying the property make sure to run Maven -> Update Project (Alt-F5) on the project in question. You may have to remove the JPA facet from the affected project manually once, by using the Project Properties page.

For those who wonder why m2e thinks the JPA facet needs to be added in the first place: This is handled by a JpaProjectConfigurator class in the m2e/WTP eclipse plugin, and can be customized by implementing factet detectors (which all must extend the AbstractFacetDetector class and registering them at the org.eclipse.m2e.wtp.facetDetectors extension point). So the facet may get activated by a plugin you've installed, or by the default detection built into the Eclipse m2e/WTP feature, which basically looks for an existing persistence.xml or orm.xml file or a JPA provider library in the projects' classpath. I had this happen when a business logic artifact was depending depending on my persistence layer artifact (with workspace resolution turned on, which may be part of the problem) that had a META-INF/persistence.xml, but the business logic artifact didn't.

For details, see M2E-WTP/New and Noteworthy/1.0.0 and The rg.eclipse.m2e.wtp.jpa.internal.configurators.JpaProjectConfigurator source code.

IMHO the accepted answer is no good advice, as it is wrong to just set the error severity to "Ignore", since then Eclipse won't warn on projects that are indeed JPA projects and thus have/need the JPA facet and consequentially should provide a persistence.xml in the expected location (naming and location can be important for artifacts deployed in Java EE environments).

In addition by actually configuring a non-JPA project correctly (i. e. without the superfluous JPA facet), Eclipse won't waste time running JPA validation and JPA change monitoring on the project. You might have noticed JPA Project Change Event Handler (waiting) in the Progress view a lot (especially when having multiple JPA projects in the workspace). These no longer run for projects that don't require JPA, when the JPA facet is removed.

3
  • I really like this way and was giving it a try. So i set the property in the mavne-module where the error occured (its an ejb-module, while the persistence unit is located in an DataAccess-module). But even after updating the (parent-)project and all modules the error still occures. Any advise?
    – bish
    Commented Jan 25, 2017 at 9:05
  • Does your project still get the jpa facet some other way? Check out the project properties? If the facet doesn't go away, neither will the warning, I would assume. Also I have every checkbox ticked on the Window -> Preferences -> Maven -> Java EE Intergration page. I'm not sure that makes a difference though. Otherwise, EJB artifacts do tend to freak out m2e (e. g. it does not understand classifiers like <type>ejb-client</type>), with all sorts of ill effects to workspace resolution and the resulting deployment assemblies. Commented Feb 9, 2017 at 13:24
  • 1
    @bish: The property may not be removed automatically. You may need to manually remove the JPA facet once after adding the property in the POM. With the property in place it should no longer be re-applied when Maven -> Update Project (Alt-F5) is invoked. Commented Mar 25, 2018 at 9:11
16
Window->Preferences->Java Persistence-> JPA-> Errors/warnings-> Project

Then change it from error to whatever you like(warning/info/ignore). You could also choose configure project specific settings if you don't want it to affect other projects

5
  • Check the answer of "Festus Tamakloe" to see the exact answer.
    – V G
    Commented Nov 29, 2013 at 14:43
  • 2
    This should be honored as the answer!
    – JanPl
    Commented Oct 22, 2015 at 19:49
  • 7
    I agree... Taking someone else's answer then writing an answer with the same info and self-accepting your own answer is not so nice I think. He could also have edited the screenshot into Sionnach733's answer. Commented Nov 15, 2015 at 3:19
  • As I have detailed in my answer this doesn't solve the problem of the JPA facet being configured, it just prevents the error from being displayed. When using m2e (Maven) use my solution, when not using m2e, remove the JPA facet from the project (assuming your project is not a JPA project). Commented Mar 17, 2019 at 16:18
  • This should be the accepted answer. For example, I have a project that doesn't have a persistence.xml in src/main/resources but does have one in src/test/resources (since it is up to dependent projects to configure exactly how they want to use the JPA entities declared in this project and having that file in the jar for this project creates problems for dependent projects) so removing the JPA facet doesn't seem to be the right solution here: it does use JPA for tests.
    – guymac
    Commented Nov 5, 2019 at 18:35
10

All of the other answers to this question deal with the issue by fooling Eclipse into not complaining about the error.

The correct solution to the issue is to remove the JPA Facet from your project. You can do that by right-clicking the project in Project Explorer, select Properties from the menu. From there, go to "Project Facets", and ensure the JPA entry is unchecked. Click Apply, then OK. Go to the Project menu and select Clean. This will remove the spurious error.

Screen shot of Project Facets

2
  • 1
    Maven creates this facet again and again. See answer by Mr. Wessel.
    – Thomas
    Commented Nov 17, 2017 at 7:36
  • 2
    This does not work. Facet selection is handled by m2e. m2e (not actually Maven itself) will re-add the JPA facet every time Maven -> Update Project (Alt-F5) is invoked, so your answer is incorrect. Funny you were compelled to downvote mine, with actually works. Commented Mar 25, 2018 at 9:07
5

I got rid of this by disabling the JPA facet for my Java project.

1
  • Please see my answer to this question for a step by step with screen shot.
    – bakoyaro
    Commented Aug 18, 2017 at 16:23
0
1. go to .setting directory of the project

2. modify org.eclipse.wst.common.project.facet.core.xml
        remove the following:
             <installed facet="jpt.jpa" version="2.0"/> 
3. Refresh the project

Cheers!!!

0

I have Eclipse Platform with this specifications: Version: Photon (4.8) Build id: I20180611-0500

I first check that the facet in:

  1. Right click on project
  2. Click on Properties
  3. Click on Project facets
  4. In the items list of facets search the JPA and validate id this is unchecked,
  5. after this check if the the error in the project tree persist, if yes: Right click on project and click in validate.
-3

I assume it is the JPA perspective that you have configred.

I just created an "empty" persistence.xml in src/main/java/META-INF. It would be seen by maven, so never gets further...It's a hack, I know, but it works...

1
  • This doesn't help at all because eclipse is still complaining persistence-unit is expected. Commented Nov 29, 2013 at 13:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.