使用@JoinColumn和Play2和Ebean进行NPE

时间:2013-12-30 18:17:46

标签: nullpointerexception playframework-2.0 ebean joincolumn

我的实体中有以下属性:

@OneToOne
@JoinColumn(unique = true)
@NotNull(message = ValidatorUtils.ERROR_NOT_NULL)
public User user;

当我刷新浏览器时,我尝试生成数据库迁移时得到以下stacktrace:

[error] application - 

! @6gmdbcgi0 - Internal server error, for (GET) [/] ->

play.api.UnexpectedException: Unexpected exception[NullPointerException: null]
    at play.core.ReloadableApplication$$anonfun$get$1$$anonfun$apply$1$$anonfun$1.apply(ApplicationProvider.scala:148) ~[play_2.10.jar:2.2.0]
    at play.core.ReloadableApplication$$anonfun$get$1$$anonfun$apply$1$$anonfun$1.apply(ApplicationProvider.scala:112) ~[play_2.10.jar:2.2.0]
    at scala.Option.map(Option.scala:145) ~[scala-library.jar:na]
    at play.core.ReloadableApplication$$anonfun$get$1$$anonfun$apply$1.apply(ApplicationProvider.scala:112) ~[play_2.10.jar:2.2.0]
    at play.core.ReloadableApplication$$anonfun$get$1$$anonfun$apply$1.apply(ApplicationProvider.scala:110) ~[play_2.10.jar:2.2.0]
    at scala.util.Success.flatMap(Try.scala:200) ~[scala-library.jar:na]
Caused by: java.lang.NullPointerException: null
    at com.avaje.ebeaninternal.server.ddl.CreateTableVisitor.isDbColumnWritten(CreateTableVisitor.java:59) ~[avaje-ebeanorm.jar:na]
    at com.avaje.ebeaninternal.server.ddl.CreateTableColumnVisitor.visitOneImported(CreateTableColumnVisitor.java:111) ~[avaje-ebeanorm.jar:na]
    at com.avaje.ebeaninternal.server.ddl.VisitorUtil.visit(VisitorUtil.java:109) ~[avaje-ebeanorm.jar:na]
    at com.avaje.ebeaninternal.server.ddl.VisitorUtil.visit(VisitorUtil.java:73) ~[avaje-ebeanorm.jar:na]
    at com.avaje.ebeaninternal.server.ddl.VisitorUtil.visitBean(VisitorUtil.java:62) ~[avaje-ebeanorm.jar:na]
    at com.avaje.ebeaninternal.server.ddl.VisitorUtil.visit(VisitorUtil.java:36) ~[avaje-ebeanorm.jar:na]

如果删除@JoinColumn注释,我的架构将正确迁移。 如何在不出现此错误的情况下将列指定为唯一?感谢。

编辑01/09/2014:添加生成的ddl

这是生成的ddl:

As we can see there is a foreign key for user

我希望生成的ddl包含以下内容: constraint uq_user_id unique (user_id)

1 个答案:

答案 0 :(得分:0)

而不是@JoinColumn(unique = true)尝试:@Column(unique=true)

此外,如果您想要将多个列组合成唯一,您可以使用:Table(name="table_name",uniqueConstraints=@UniqueConstraint(columnNames={"column1","column2"}))