Mysql Scala Slick:使用直接嵌入的查询不';行不通
我使用以下代码从mysql表请求项(Account类只是一个表示数据库字段的case类) 线路Mysql Scala Slick:使用直接嵌入的查询不';行不通,mysql,scala,orm,scalaquery,slick,Mysql,Scala,Orm,Scalaquery,Slick,我使用以下代码从mysql表请求项(Account类只是一个表示数据库字段的case类) 线路 val r=backend.toList(res) 引发以下异常: [ToolBoxError: reflective typecheck has failed: ambiguous implicit values: both value StringCanBuildFrom in object Predef of type => scala.collection.generic.CanBui
val r=backend.toList(res)
引发以下异常:
[ToolBoxError: reflective typecheck has failed: ambiguous implicit values: both value StringCanBuildFrom in object Predef of type => scala.collection.generic.CanBuildFrom[String,Char,String] and method conforms in object Predef of type [A]=> <:<[A,A] match expected type T]
这意味着类型与mysql类型不匹配。ie id应该是一个Int而不是一个长。不确定,但是试试“db.withSession{…”没有什么区别:(不熟悉slick,但是这个toList方法是什么?你不能明确地告诉编译器你需要一个List[Account]?在ScalaQuery上,我做一些类似List[Foo](someQuery)的事情,其中list是一个助手方法,它在查询中调用SQ的list方法并强制转换到给定的T。不是类型安全的,但非常方便……也不熟悉slick。SlickBackend.toList是我发现的一种实际执行查询的方法。类型推断器告诉我r是list[String]类型,正如我所期望的那样。错误就是线索,帮助编译器并显式指定类型。
[ToolBoxError: reflective typecheck has failed: ambiguous implicit values: both value StringCanBuildFrom in object Predef of type => scala.collection.generic.CanBuildFrom[String,Char,String] and method conforms in object Predef of type [A]=> <:<[A,A] match expected type T]
@table("account")
case class Account (
@column("ID") id: Long,
...
@column("Name") name: String,
...
)