使用Play! 1.2.4,Scala和Squeryl与Postgres
像往常一样执行一个简单的数据库插入,突然之间数据库已经开始像疯了一样抛出NullPointerExceptions。所有这些都是在我创建了一个可以自动将某人添加到帐户的电子邮件邀请处理程序时启动的。
代码:
插入发生的Member.scala:
def insert(member:Member) = DB.members.insert(member)
上面的代码就是Play!表示发生NullPointerException。当我在val member
下面运行调试器时,它会显示一个具有适当值的有效Member类。
def invitation(s:Option[String]) = {
s match {
case Some(s) => {
val invite = Invite.getByKey(s)
invite match {
case Some(invite) => {
User.search(invite.email) match {
case Some(user) => {
val member = new Member(user.id,invite.accountId,null)
Member.insert( member )
session.clear()
flash += "notice" -> "Success! Please login to continue."
Action(Authentication.login)
}
case _ => Action(Users.`new`(s))
}
}
case None => Error("Invite does not exist.")
}
}
case None => Action(Application.index)
}
}
堆栈跟踪:
Internal Server Error (500) for request GET /invitation?s=e3dfd60e-bc07-496a-918
1-97c6ea4b0b71
Execution exception (In /app/models/Member.scala around line 59)
NullPointerException occured : null
! play.exceptions.JavaExecutionException
! at play.mvc.ActionInvoker.invoke(ActionInvoker.java:231)
! at Invocation.HTTP Request(Play!)
! Caused by: java.lang.NullPointerException
! at org.squeryl.internals.FieldMetaData.get(FieldMetaData.scala:260)
! at org.squeryl.internals.DatabaseAdapter$class.writeValue(DatabaseAdapte
r.scala:456)
! at org.squeryl.adapters.PostgreSqlAdapter.writeValue(PostgreSqlAdapter.s
cala:24)
! at org.squeryl.internals.DatabaseAdapter$$anonfun$writeInsert$2.apply(Da
tabaseAdapter.scala:415)
! at org.squeryl.internals.DatabaseAdapter$$anonfun$writeInsert$2.apply(Da
tabaseAdapter.scala:415)
! at org.squeryl.internals.DatabaseAdapter$class.writeInsert(DatabaseAdapt
er.scala:415)
! at org.squeryl.adapters.PostgreSqlAdapter.writeInsert(PostgreSqlAdapter.
scala:70)
! at org.squeryl.Table$$anonfun$insert$1.apply(Table.scala:39)
! at org.squeryl.logging.StackMarker$.lastSquerylStackFrame(StatisticsList
ener.scala:52)
! at org.squeryl.Table.insert(Table.scala:34)
! at models.Member$.insert(Member.scala:59)
! at controllers.Invites$.invitation(Invites.scala:24)
! at play.mvc.ActionInvoker.invokeWithContinuation(ActionInvoker.java:548)
! at play.mvc.ActionInvoker.invoke(ActionInvoker.java:502)
! at play.mvc.ActionInvoker.invokeControllerMethod(ActionInvoker.java:496)
! at play.mvc.ActionInvoker.invokeControllerMethod(ActionInvoker.java:473)
! at play.mvc.ActionInvoker.invoke(ActionInvoker.java:161)
! ... 1 more
帮助赞赏
以前从未见过这可能是一个简单的修复,非常感谢您的帮助。