2013-12-24 49 views
0

我知道orphanRemoval属性存在于hibernate-jpa-2.1-api-1.0.0.Final.jar中,这是我的项目中使用的库。Maven中的依赖问题

我加了Maven的依赖性:

<dependency> 
    <groupId>org.hibernate</groupId> 
    <artifactId>hibernate-core</artifactId> 
    <version>4.3.0.Final</version> 
</dependency> 

我仍然得到错误:在该行The attribute orphanRemoval is undefined for the annotation type OneToMany

@OneToMany(fetch = FetchType.LAZY, mappedBy = "id.store", cascade = { 
     CascadeType.PERSIST, CascadeType.MERGE }, orphanRemoval=true) 

这里有什么问题,我能做些什么来解决这个问题?

编辑:这是我的依赖关系:

<dependencies> 
    <dependency> 
     <groupId>com.sun.jersey</groupId> 
     <artifactId>jersey-server</artifactId> 
     <version>${jersey-version}</version> 
    </dependency> 
    <dependency> 
     <groupId>com.sun.jersey</groupId> 
     <artifactId>jersey-json</artifactId> 
     <version>${jersey-version}</version> 
    </dependency> 
    <dependency> 
     <groupId>junit</groupId> 
     <artifactId>junit</artifactId> 
     <version>4.8.2</version> 
     <scope>test</scope> 
    </dependency> 
    <dependency> 
     <groupId>com.sun.jersey</groupId> 
     <artifactId>jersey-client</artifactId> 
     <version>${jersey-version}</version> 
     <scope>test</scope> 
    </dependency> 
    <dependency> 
     <groupId>org.glassfish.distributions</groupId> 
     <artifactId>web-all</artifactId> 
     <version>10.0-build-20080430</version> 
     <scope>test</scope> 
    </dependency> 
    <dependency> 
     <groupId>org.glassfish.embedded</groupId> 
     <artifactId>gf-embedded-api</artifactId> 
     <version>1.0-alpha-4</version> 
     <scope>test</scope> 
    </dependency> 
    <dependency> 
     <groupId>javax.servlet</groupId> 
     <artifactId>servlet-api</artifactId> 
     <version>2.5</version> 
     <scope>provided</scope> 
    </dependency> 
    <dependency> 
     <groupId>org.hibernate</groupId> 
     <artifactId>hibernate-core</artifactId> 
     <version>4.3.0.Final</version> 
    </dependency> 
</dependencies> 
+1

它也是'hibernate-jpa-2.0',也就是说, Java EE 6.你确定你正在使用'javax.persistence.OneToMany'吗? –

+0

添加错误堆栈跟踪有更好的主意。 –

+0

@suresh这是一个编译错误。在那。 –

回答

1

在GlassFish Web的所有的依赖也包含了JPA的包,它包含从2008-04-30老版本的它(作为版本的人造物表示,可能是JPA 1.0)。

您可以在此处看到此依赖关系中包含的软件包:http://mvnrepository.com/artifact/org.glassfish.distributions/web-all/10.0-build-20080430

+0

非常感谢!我删除了参考,它工作。由于我使用eclipse来构建项目并使用'jersey-quickstart-webapp'原型,因此它会自动包含该引用。因为这是我的第一个Maven项目,所以我不知道什么是错的。 – AntonioJunior

+0

我对Maven文物的一点经验表明,它们几乎全部都是过时的,不应该使用。你最好仔细选择你的依赖关系。我还建议学习gradle而不是Maven:它是一个非常优秀的构建工具,它可以很好地处理来自Maven存储库的依赖关系。 –

1

添加了hibernate-jpa-2.0-api-1.0.0.Final.jar并删除了persistence.jar,在参考库中没有orphanRemoval()方法javax.persistence包。这解决了错误

"The attribute orphanRemoval is undefined for the annotation type OneToMany".

+0

它在这个jar中可用 - hibernate-jpa-2.0-api-1.0.0.Final.jar – lakshmi