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

Panayiotis Karabassis picture Panayiotis Karabassis · Jan 4, 2011 · Viewed 24.4k times · Source

I am getting this error:

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

These are the jars in my classpath:

com.sun.faces/jsf-api/jars/jsf-api-2.0.0.jar
com.sun.faces/jsf-impl/jars/jsf-impl-2.0.0.jar
org.apache.myfaces.orchestra/myfaces-orchestra-core20/jars/myfaces-orchestra-core20-1.5-SNAPSHOT.jar
commons-lang/commons-lang/jars/commons-lang-2.1.jar
commons-logging/commons-logging/jars/commons-logging-1.1.1.jar
org.springframework/spring/jars/spring-2.5.6.jar
commons-el/commons-el/jars/commons-el-1.0.jar
org.richfaces.ui/richfaces-ui/jars/richfaces-ui-3.3.3.Final.jar
org.richfaces.framework/richfaces-api/jars/richfaces-api-3.3.3.Final.jar
commons-collections/commons-collections/jars/commons-collections-3.2.jar
commons-beanutils/commons-beanutils/jars/commons-beanutils-1.8.0.jar
org.richfaces.framework/richfaces-impl-jsf2/jars/richfaces-impl-jsf2-3.3.3.Final.jar
com.sun.facelets/jsf-facelets/jars/jsf-facelets-1.1.14.jar
org.hibernate/hibernate-core/jars/hibernate-core-3.6.0.Final.jar
antlr/antlr/jars/antlr-2.7.6.jar
dom4j/dom4j/jars/dom4j-1.6.1.jar
org.hibernate/hibernate-commons-annotations/jars/hibernate-commons-annotations-3.2.0.Final.jar
org.slf4j/slf4j-api/jars/slf4j-api-1.6.1.jar
org.hibernate.javax.persistence/hibernate-jpa-2.0-api/jars/hibernate-jpa-2.0-api-1.0.0.Final.jar
javax.transaction/jta/jars/jta-1.1.jar
org.hibernate/hibernate-c3p0/jars/hibernate-c3p0-3.6.0.Final.jar
c3p0/c3p0/jars/c3p0-0.9.1.jar
org.hibernate/hibernate-entitymanager/jars/hibernate-entitymanager-3.6.0.Final.jar
cglib/cglib/jars/cglib-2.2.jar
asm/asm/jars/asm-3.1.jar
javassist/javassist/jars/javassist-3.12.0.GA.jar
org.hibernate/hibernate-search/jars/hibernate-search-3.3.0.Final.jar
org.hibernate/hibernate-search-analyzers/jars/hibernate-search-analyzers-3.3.0.Final.jar
org.apache.lucene/lucene-core/jars/lucene-core-3.0.3.jar
org.apache.lucene/lucene-analyzers/jars/lucene-analyzers-3.0.3.jar
mysql/mysql-connector-java/jars/mysql-connector-java-5.1.13.jar
com.ocpsoft/prettyfaces-jsf2/jars/prettyfaces-jsf2-3.0.1.jar
commons-digester/commons-digester/jars/commons-digester-2.0.jar
org.slf4j/slf4j-log4j12/jars/slf4j-log4j12-1.6.1.jar
log4j/log4j/bundles/log4j-1.2.16.jar
xom/xom/jars/xom-1.2.5.jar
xml-apis/xml-apis/jars/xml-apis-1.3.03.jar
xerces/xercesImpl/jars/xercesImpl-2.8.0.jar
xalan/xalan/jars/xalan-2.7.0.jar
org.jboss.jsfunit/jboss-jsfunit-core/jars/jboss-jsfunit-core-1.3.0.Final.jar
net.sourceforge.htmlunit/htmlunit/jars/htmlunit-2.8.jar
xalan/xalan/jars/xalan-2.7.1.jar
xalan/serializer/jars/serializer-2.7.1.jar
xml-apis/xml-apis/jars/xml-apis-1.3.04.jar
commons-collections/commons-collections/jars/commons-collections-3.2.1.jar
commons-lang/commons-lang/jars/commons-lang-2.4.jar
org.apache.httpcomponents/httpclient/jars/httpclient-4.0.1.jar
org.apache.httpcomponents/httpcore/jars/httpcore-4.0.1.jar
commons-codec/commons-codec/jars/commons-codec-1.4.jar
org.apache.httpcomponents/httpmime/jars/httpmime-4.0.1.jar
org.apache.james/apache-mime4j/jars/apache-mime4j-0.6.jar
net.sourceforge.htmlunit/htmlunit-core-js/jars/htmlunit-core-js-2.8.jar
xerces/xercesImpl/jars/xercesImpl-2.9.1.jar
net.sourceforge.nekohtml/nekohtml/jars/nekohtml-1.9.14.jar
net.sourceforge.cssparser/cssparser/jars/cssparser-0.9.5.jar
org.w3c.css/sac/jars/sac-1.3.jar
commons-io/commons-io/jars/commons-io-1.4.jar
cactus/cactus/jars/cactus-13-1.7.1.jar
cactus/cactus-ant/jars/cactus-ant-13-1.7.1.jar
commons-httpclient/commons-httpclient/jars/commons-httpclient-2.0.2.jar
junit/junit/jars/junit-3.8.1.jar
aspectj/aspectjrt/jars/aspectjrt-1.2.1.jar
cargo/cargo/jars/cargo-0.5.jar
ant/ant/jars/ant-1.5.4.jar

and this is my ivy.xml:

<dependencies>

        <!-- JSF 2.0 RI -->
        <dependency org="com.sun.faces" name="jsf-api" rev="2.0.0"/>
        <dependency org="com.sun.faces" name="jsf-impl" rev="2.0.0"/>

        <!-- MyFaces Orchestra -->
        <dependency org="org.apache.myfaces.orchestra" name="myfaces-orchestra-core20" rev="1.5-SNAPSHOT"/>
        <dependency org="org.springframework" name="spring" rev="2.5.6"/>
        <dependency org="commons-el" name="commons-el" rev="1.0"/>

        <!-- RichFaces -->
        <dependency org="org.richfaces.ui" name="richfaces-ui" rev="3.3.3.Final"/>
        <dependency org="org.richfaces.framework" name="richfaces-impl-jsf2" rev="3.3.3.Final"/>
        <dependency org="com.sun.facelets" name="jsf-facelets" rev="1.1.14"/>

        <!-- Hibernate -->
        <dependency org="org.hibernate" name="hibernate-core" rev="3.6.0.Final"/>
        <dependency org="org.hibernate" name="hibernate-c3p0" rev="3.6.0.Final"/>
        <dependency org="org.hibernate" name="hibernate-entitymanager" rev="3.6.0.Final"/>
        <dependency org="org.hibernate" name="hibernate-search" rev="3.3.0.Final"/>
        <dependency org="mysql" name="mysql-connector-java" rev="5.1.13"/>

        <!-- PrettyFaces -->
        <dependency org="com.ocpsoft" name="prettyfaces-jsf2" rev="3.0.1"/>

        <!-- SLF4J -->
        <dependency org="org.slf4j" name="slf4j-api" rev="1.6.1"/>
        <dependency org="org.slf4j" name="slf4j-log4j12" rev="1.6.1"/>

        <!-- XOM  -->
        <dependency org="xom" name="xom" rev="1.2.5"/>

        <!-- JSF Unit -->
        <dependency org="org.jboss.jsfunit" name="jboss-jsfunit-core" rev="1.3.0.Final" conf="development"/>

    </dependencies>

I am deploying to tomcat 6.0

Update

After the answer below, I solved this by adding the following dependency to my ivy.xml:

<dependency org="org.hibernate.javax.persistence" name="hibernate-jpa-2.0-api" rev="1.0.0.Final"/>

then putting this jar above everything else under Eclipse's build order tab.

I was using JRE/JDK 6.

Answer

Christian Kuetbach picture Christian Kuetbach · Jan 4, 2011

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.