java.lang.NoSuchMethodError: javax.persistence.OneToMany.orphanRemoval()Z

眉间皱痕 提交于 2019-11-28 00:59:22
Christian Kuetbach

You have a wrong version of the Java Persistence API:

See OneToMany.orphanRemoval() Documentation

Since: Java Persinstence 2.0

It is not included with JEE5.

Edit: http://wiki.eclipse.org/EclipseLink/Examples/JPA/Tomcat_Web_Tutorial

Limitations to JPA

  • As Tomcat is not a JEE5 compatible server, there are some limitiations to JPA.

    • No dynamic weaving (instrumentation) - static weaving of entities is still available via EclipseLink
    • No @EJB injection of a session bean (containing the EntityManager) is available - use the persistence factory and manager directly
    • No @PersistenceContext injection of a container managed persistence unit is available - use Persistence.createEntityManagerFactory(JTA_PU_NAME)

If the Tomcat is not JEE5 compliant, I am sure it will not be JEE6 compliant.

I solved this issue by including the persistence-api artifact as a dependency in my war project. I used its latest version 1.0.2:

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