Search code examples
javaeclipsejpaeclipselinkcompiler-warnings

Eclipse Warnings: class javax.persistence.* not found


This is my first time really playing around with Java development using Eclipse. I am trying to use EclipseLink's implementation of the JPA. I moved all of my entities into a separate package "entities". I have the persistence.xml in a separate JPA project called "dataModeling".

package explorer

Everything builds and runs fine.

Just about every project depends on my entities. However, I'm seeing a warning Class javax.persistence.Entity not found - continuing with a stub., etc. showing up because the dependent projects don't reference EclipseLink.

warning messages

The solution is to go into each dependent project's properties and under Java Build Path > Libraries, click Add Library, then User Library and then select EclipseLink.

However, to me, it doesn't make sense to reference EclipseLink in every project! That's an implementation detail I don't want to burden other projects with. It looks like this is happening because the other projects see the annotations and don't recognize them.

So the real question is: how can I use JPA (via annotations) without every other project needing to reference my JPA implementation?


Solution

  • Thanks to @neil-stockton and @chris, I was able to figure out what was going on. Most JPA implementations have a copy of the javax.persistence JAR floating around somewhere. Most of them are bundled with everything else, leading to my dependency nightmare. There doesn't appear to be a de facto implementation floating around.

    In my case, I used the copy that showed up under my Eclipse plugins directory. These annotations were truly empty in that did not have any unwanted dependencies. The JAR file (javax.persistence._<version>.jar) only showed up after I added the Dali and EclipseLink plugins (one or the other).