I have been receiving an UnexpectedNullableFound error with my Scala application and I was hoping for some assistance on how to correct this.
The error:-
[error] application - Unable to log user in. An exception was thrown
java.lang.RuntimeException: Left(UnexpectedNullableFound(ColumnName(.language,Some(language)))) at anorm.MayErr$$anonfun$get$1.apply(MayErr.scala:35) ~[anorm_2.11-2.4.0.jar:2.4.0] at anorm.MayErr$$anonfun$get$1.apply(MayErr.scala:34) ~[anorm_2.11-2.4.0.jar:2.4.0] at scala.util.Either.fold(Either.scala:98) ~[scala-library-2.11.12.jar:na] at anorm.MayErr.get(MayErr.scala:34) ~[anorm_2.11-2.4.0.jar:2.4.0]
at anorm.Row$class.unsafeGet(Row.scala:103) ~[anorm_2.11-2.4.0.jar:2.4.0]
at anorm.Cursor$ResultRow.unsafeGet(Cursor.scala:77) ~[anorm_2.11-2.4.0.jar:2.4.0] at anorm.Row$class.apply(Row.scala:80) ~[anorm_2.11-2.4.0.jar:2.4.0] at anorm.Cursor$ResultRow.apply(Cursor.scala:77) ~[anorm_2.11-2.4.0.jar:2.4.0]
at models.UserModel$$anonfun$findUserByEmailAndPassword$1$$anonfun$apply$9.apply(UserModel.scala:162) ~[classes/:na]
at models.UserModel$$anonfun$findUserByEmailAndPassword$1$$anonfun$apply$9.apply(UserModel.scala:156) ~[classes/:na]
And this is the code where I think it might be causing this error:-
def findUserByEmailAndPassword(email: String, password: String, browserHeaders: String, ip: String): Option[SocialUser] = DB.withConnection(db) { implicit c =>
SQL"""
select * from find_user_by_email_and_password($email, $password, $browserHeaders, inet($ip))
"""().map(row => (row[Option[Long]]("id"),
row[Option[String]]("email"),
row[Option[Int]]("verification"),
row[Option[Boolean]]("on_mailing_list"),
row[Option[Boolean]]("tfa_enabled"),
row[Option[String]]("pgp"),
row[String]("language")) match {
case (Some(id: Long),
Some(email: String),
Some(verification: Int),
Some(on_mailing_list: Boolean),
Some(tfa_enabled: Boolean),
pgp: Option[String],
language: String) =>
Some(SocialUser(id, email, verification, language, on_mailing_list, tfa_enabled, pgp))
case _ =>
None
}
).head
Any help would be greatly appreciated.
答案 0 :(得分:1)
您将从row[String]("language")
列中提取language
,但此列包含NULL
值。
您需要将其写为row[Option[String]]("language")
或在数据库方案中设置语言列NOT NULL
。