使用Ebean播放Play2空指针异常

时间:2013-07-14 03:47:14

标签: nullpointerexception playframework-2.0 ddl ebean

我正在使用Play2和Ebean作为ORM开发应用程序。由于以下错误,我无法启动我的应用程序:

[warn] c.a.e.s.c.DefaultServer - JMX beans for Ebean server [default] already registered. Will try unregister/registerEbean:server=default2,function=Logging
[warn] c.a.ebean.Ebean - Existing EbeanServer [default] is being replaced?
[error] application - 

! @6f14elgpb - 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:150) ~[play_2.10.jar:2.1.2]
    at play.core.ReloadableApplication$$anonfun$get$1$$anonfun$apply$1$$anonfun$1.apply(ApplicationProvider.scala:114) ~[play_2.10.jar:2.1.2]
    at scala.Option.map(Option.scala:145) ~[scala-library.jar:na]
    at play.core.ReloadableApplication$$anonfun$get$1$$anonfun$apply$1.apply(ApplicationProvider.scala:114) ~[play_2.10.jar:2.1.2]
    at play.core.ReloadableApplication$$anonfun$get$1$$anonfun$apply$1.apply(ApplicationProvider.scala:112) ~[play_2.10.jar:2.1.2]
    at scala.util.Either$RightProjection.flatMap(Either.scala:523) ~[scala-library.jar:na]
Caused by: java.lang.NullPointerException: null
    at com.avaje.ebeaninternal.server.ddl.CreateTableVisitor.isDbColumnWritten(CreateTableVisitor.java:58) ~[avaje-ebeanorm-server.jar:na]
    at com.avaje.ebeaninternal.server.ddl.CreateTableColumnVisitor.visitOneImported(CreateTableColumnVisitor.java:117) ~[avaje-ebeanorm-server.jar:na]
    at com.avaje.ebeaninternal.server.ddl.VisitorUtil.visit(VisitorUtil.java:109) ~[avaje-ebeanorm-server.jar:na]
    at com.avaje.ebeaninternal.server.ddl.VisitorUtil.visit(VisitorUtil.java:73) ~[avaje-ebeanorm-server.jar:na]
    at com.avaje.ebeaninternal.server.ddl.VisitorUtil.visitBean(VisitorUtil.java:62) ~[avaje-ebeanorm-server.jar:na]
    at com.avaje.ebeaninternal.server.ddl.VisitorUtil.visit(VisitorUtil.java:36) ~[avaje-ebeanorm-server.jar:na]
[trace] play - No handler, got direct result: SimpleResult(500, Map(Content-Type -> text/html; charset=utf-8))

我不明白发生了什么,服务器启动良好,我试图重启mysql但没有改变。 它似乎是来自Ebean DDL生成器的错误,但我该如何调试呢?

感谢您的帮助。

编辑:如果我在application.conf中禁用了evolution插件

# Evolutions
# ~~~~~
# You can disable evolutions if needed
evolutionplugin=disabled

我的应用程序启动(但数据库未更新...)

编辑2 :我在应用程序级别激活了TRACE日志并更新了堆栈跟踪,以下几行:

[warn] c.a.e.s.c.DefaultServer - JMX beans for Ebean server [default] already registered. Will try unregister/registerEbean:server=default2,function=Logging
[warn] c.a.ebean.Ebean - Existing EbeanServer [default] is being replaced?

1 个答案:

答案 0 :(得分:2)

好的,我发现了问题所在。我有一个客户实体,其中包含带注释的字段:

@OneToOne(cascade = CascadeType.ALL)
@JoinColumn(unique = true)
@NotNull
public User user;

如果我在JoinColumn注释中添加name = "user_id",,则错误不再发生......所以这有效:

@OneToOne(cascade = CascadeType.ALL)
@JoinColumn(name = "user_id", unique = true)
@NotNull
public User user;

但是在所有情况下,我的user_id列上的唯一约束不会应用于数据库中。你们其中一个人有想法吗?这是Ebean的限制吗?

感谢。