Eclipse Warnings: class javax.persistence.* not found

a 夏天 提交于 2019-12-05 21:28:45

Your pom.xml should contain:

<dependency>
    <groupId>org.eclipse.persistence</groupId>
    <artifactId>eclipselink</artifactId>
    <version>2.5.1</version>
</dependency>
<dependency>
    <groupId>org.eclipse.persistence</groupId>
    <artifactId>javax.persistence</artifactId>
    <version>2.0.0</version>
    <scope>compile</scope>
</dependency>

the first one is Eclipse-Link (which you already have), the second one is Persistence API which is lacking.

If you are not using maven - make sure that javax.persistence-2.0.0.jar is on your classpath.

Note that this is version 2.0.0, the newest is 2.1.0

update The project which makes use of EntityManager should have these dependences. Putting entities and persistence.xml in separate jar file still requires the other project that uses it to fulfill above dependencies.

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).

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!