0

I use the following code to request items from a mysql table (The Account class just is a case class representing the database fields)

val res = Queryable[Account].map(_.name)

val db = Database.forURL("jdbc:mysql://localhost:3306/databasename", driver = "com.mysql.jdbc.Driver", user="username", password="password")
val backend = new SlickBackend(MySQLDriver, AnnotationMapper)

db withSession {
  val r=backend.toList(res)
  println(r.toString)
}

The line

val r=backend.toList(res)

throws the following exception:

[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] 

What could be the reason for it? I'm using Scala 2.10.0-RC1 and Slick 0.11.2.

Here the way the Account class looks like:

@table("account")
case class Account (
    @column("ID") id: Long,
    ...
    @column("Name") name: String,
    ...
)
Heinzi
  • 5,793
  • 4
  • 40
  • 69
  • not sure, but try "db.withSession {..." – virtualeyes Nov 09 '12 at 14:07
  • Doesn't make a difference :( – Heinzi Nov 10 '12 at 15:53
  • not familiar with slick, but what is this toList method? Can you not explicitly tell the compiler that you are expecting a List[Account]? On ScalaQuery I do something like list[Foo](someQuery), where list is a helper method that invokes SQ's list method on the query and casts to the given T. Not typesafe but highly convenient.... – virtualeyes Nov 10 '12 at 16:22
  • Not familiar with slick too. SlickBackend.toList was a way I found to actually execute the query. The type inferencer tells me that r is of type List[String], as I'd expect it. – Heinzi Nov 11 '12 at 14:29
  • well the error is the clue, give the compiler a hand and explicitly specify the type. – virtualeyes Nov 11 '12 at 14:34

1 Answers1

0

This means the types don't match the mysql types. ie id should be a Int not a Long.

glymor
  • 1