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

时间:2011-01-04 08:15:49

标签: java maven ivy hibernate-search

我收到此错误:

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

这些是我的类路径中的jar:

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

这是我的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>

我正在部署到tomcat 6.0

更新

在下面的答案之后,我通过将以下依赖项添加到我的ivy.xml来解决这个问题:

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

然后将这个jar放在Eclipse的构建顺序选项卡下的其他所有内容中。

我使用的是JRE / JDK 6.

2 个答案:

答案 0 :(得分:10)

您的Java Persistence API版本错误:

请参阅OneToMany.orphanRemoval() Documentation

Since: Java Persinstence 2.0

它不包含在JEE5中。

修改 http://wiki.eclipse.org/EclipseLink/Examples/JPA/Tomcat_Web_Tutorial

  

JPA的限制

     
      
  • 由于Tomcat不是兼容JEE5的服务器,因此JPA存在一些限制。

         
        
    • 没有动态编织(仪器) - 通过EclipseLink
    • 仍然可以实现静态编织实体   
    • 没有@EJB注入会话bean(包含EntityManager)可用 - 直接使用持久性工厂和经理
    •   
    • 没有@PersistenceContext注入容器管理的持久性单元 - 使用Persistence.createEntityManagerFactory(JTA_PU_NAME)
    •   
  •   

如果Tomcat不符合JEE5,我相信它不会符合JEE6标准。

答案 1 :(得分:0)

我通过在我的war项目中包含persistence-api工件作为依赖项解决了这个问题。我使用了它的最新版本1.0.2:

    <dependency>
        <groupId>javax.persistence</groupId>
        <artifactId>persistence-api</artifactId>
        <version>1.0.2</version> 
    </dependency>