【问题标题】:javax.persistence annotations missing optional elements?javax.persistence 注释缺少可选元素?
【发布时间】:2016-07-19 08:37:56
【问题描述】:

我们正在将 Play 框架应用程序从 2.3.10 升级到 2.4.8,然后从 Ebean 3.x 升级到 4.6.2。

我现在看到编译错误,指出某些 javax.persistence 注释缺少字段。两个版本的 Ebean 都依赖于 javax.persistence 的 1.0 版本。

奇怪的是,IntelliJ 将注释显示为缺少可选元素,但注释的 Javadoc 提到了可选元素。请注意,编译也失败了

例如,这是 IntelliJ 为javax.persistence.UniqueConstraint 显示的源代码:

/**
 * This annotation is used to specify that a unique constraint 
 * is to be included in the generated DDL for a primary or secondary table.
 *
 * <pre>
 *    Example:
 *    &#064;Entity
 *    &#064;Table(
 *        name="EMPLOYEE", 
 *        uniqueConstraints=
 *            &#064;UniqueConstraint(columnNames={"EMP_ID", "EMP_NAME"})
 *    )
 *    public class Employee { ... }
 * </pre>
 *
 * @since Java Persistence 1.0
 */
@Target({TYPE}) 
@Retention(RUNTIME)

public @interface UniqueConstraint {

    /** (Required) An array of the column names that make up the constraint. */
    String[] columnNames();
}

【问题讨论】:

  • 什么“可选”元素?您显示 JPA 1.0。您需要 JPA 2.0 或 JPA 2.1。所以拿起后来的 JPA API jar 将它集成到你的构建中,你会看到 JPA 更高版本的所有注释属性
  • 另见 JPA javadocs,它非常清楚地说明“名称”被添加到 JPA 2.0 docs.oracle.com/javaee/7/api/javax/persistence/…
  • 啊,我明白了。这很奇怪;以前一定是在导入 JPA 2.x。无论如何,这解决了它。谢谢!

标签: java jpa intellij-idea playframework ebean


【解决方案1】:

您当前正在使用 JPA 1.0(在您的构建过程中某处,以及 IDEA 向您展示的内容)。 UniqueConstraint annotation 的“名称”属性是在 JPA 2.0 中引入的。您需要更改 IDEA 的构建以使用 JPA 2.0。

【讨论】:

    猜你喜欢
    • 2013-09-17
    • 1970-01-01
    • 1970-01-01
    • 2019-09-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-05-06
    相关资源
    最近更新 更多