【问题标题】:Issue with dependency in MavenMaven中的依赖问题
【发布时间】:2014-01-12 07:43:58
【问题描述】:

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

我添加了 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>

【问题讨论】:

  • 它也在hibernate-jpa-2.0 中,即。 Java EE 6。你确定你使用的是javax.persistence.OneToMany
  • 添加错误堆栈跟踪以获得更好的想法。
  • @suresh 这是一个编译错误。它就在那里。
  • 我们可以查看您的其余依赖项吗?
  • 是的,导入javax.persistence.OneToMany 在那里。我检查了项目中的 Maven 依赖树,它包含hibernate-jpa-2.1-api-1.0.0.Final.jar。我还检查了课堂OneToMany。它包含cascadefetchmappedByorphanRemovaltargetEntity

标签: java eclipse hibernate maven jpa


【解决方案1】:

glassfish web-all 依赖项还包含 JPA 包,它包含旧版本(从 2008-04-30 开始,如人工制品的版本所示,因此可能是 JPA 1.0)。

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

【讨论】:

  • 非常感谢!我删除了引用并且它起作用了。由于我使用 eclipse 构建项目并使用了 jersey-quickstart-webapp 原型,因此它自动包含了该引用。因为这是我的第一个 Maven 项目,所以我不知道出了什么问题。
  • 我对 Maven 人工制品的小经验表明,几乎所有这些人工制品都已过时,不应使用。您最好仔细选择您的依赖项。而且我还建议学习 gradle 而不是 Maven:它是一个非常出色的构建工具,可以很好地处理来自 Maven 存储库的依赖项。
【解决方案2】:

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

"注解类​​型的属性orphanRemoval未定义 一对多”。

【讨论】:

  • 在这个 jar 中可用 - hibernate-jpa-2.0-api-1.0.0.Final.jar
猜你喜欢
  • 2020-10-21
  • 1970-01-01
  • 2011-06-11
  • 1970-01-01
  • 2021-12-06
  • 2011-10-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多