How is this "type mismatch"?

found : (Int, String, Option[java.lang.String]) required: (Int, String, Option[java.lang.String]) 

Relevant Code:

 object M extends Table[(Int, String, Option[String])]("table") { def msaid = column[Int]("msaid", O NotNull) def name = column[String]("name", O DBType "varchar(255)") def shape = column[Option[String]]("shape") def * = msaid ~ name ~ shape type T = (Int, String, Option[java.lang.String]) def apply(msa: T) = 1 def q() = db withSession { s: Session => (for (r <- M) yield M(*)).list()(s) } ^ ^ ... 

I also tried

  type T = (Int, String, Option[String]) 

The ultimate goal is that I want all the selected columns to be converted to an object with named accessor, instead of being a tuple.

 Scala version 2.9.2 (Java HotSpot(TM) 64-Bit Server VM, Java 1.7.0_07). 

UPDATE:

Here's the Gist problem (slightly simplified from the code above and eliminates any confusion String / java.lang.String "using only Int.)

+4
source share
1 answer

The error message was not used to tell you what TupleN was like, although I think it was improved at some point. The mismatch between the tuple and n args. Or not.

fix is located at 2.9.2. I notice that your .sbt uses 2.9.1 scalaquery, in case that matters. And aren't scala -tools.org out of date? Sorry for half the help.

Speaking as a non-user, it looks like Projection2 is not the Tuple you are looking for, although Product:

 class Projection2 [T1, T2] extends (Column[T1], Column[T2]) with Projection[(T1, T2)] 

REPLing:

 scala> M.column[Int]("id") ~ M.column[Int]("n") res1: (Int, Int) = Projection2 scala> M(res1) <console>:23: error: type mismatch; found : (Int, Int) required: (Int, Int) M(res1) ^ scala> M.apply def apply(v: (Int, Int)): Int scala> M.apply((1,2)) res3: Int = 1 
+3
source

All Articles