2013-12-24 54 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