I have a problem with slick. It looks like after using it scala is not a statically typed language anymore:)
I used slick to call a SqlServer stored procedure that should return some values (and it does when I call the procedure directly in my SQL client). Unfortunately as you can see below the result is that I have a val with type Option[ProcessUserRoleDto], with ProcessUserRoleDto being just an ordinary case class, that in fact hold value of Some(1) and the '1' is of type java.lang.Integer. How is this possible? Do you have any ideas how to resolve this problem?
case class ProcessUserRoleDto(
processUserRoleId: Int,
processUserId: Int,
processRoleId: Int,
dataCollectionId: Int,
recognizingInstanceId: Int,
processRoleName: String,
dataCollectionName: String,
recognizingInstanceName: String,
isActive: Boolean)
def assign(dto: ProcessUserRoleAssignDto): Future[Option[ProcessUserRoleDto]] = {
val db = implicitly[SQLServerDriver.backend.DatabaseDef]
val sql = sql"exec EVO.spProcessUserRoleAssignToRecognizingInstance ${dto.ProcessUser_ID}, ${dto.ProcessRole_ID}, ${dto.RecognizingInstance_ID}"
implicit val registerProcessUserResult = GetResult { r =>
ProcessUserRoleDto(r.<<, r.<<, r.<<, r.<<, r.<<, r.<<, r.<<, r.<<, r.<<)
}
val resultFut: Future[Option[ProcessUserRoleDto]] = db
.run(sql.as[ProcessUserRoleDto])
.map(_.headOption)
val singleResult: Option[ProcessUserRoleDto] = Await.result(resultFut, 10 seconds)
println(s"singleResult = $singleResult")
// in runtime result was: Some(1)
// WTF ?!?
println(s"class inside Some() = ${singleResult.get.getClass.getCanonicalName}")
// in runtime result is: java.lang.Integer
println(s"Option[Class] = ${singleResult.map(_.getClass.getCanonicalName)}")
// here exception is thrown: java.lang.ClassCastException: java.lang.Integer cannot be cast to ProcessUserRoleDto
}