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

相关代码:

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) }
                                                                 ^
                                                                 ^
...

我也试过

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

最终目标是我希望所有选定的列都转换为具有命名访问器的对象,而不是元组。

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

更新:

这是问题的要点(从上面的代码略微简化,并通过仅使用 Int 消除了任何 String/java.lang.String “混淆”。)

4

1 回答 1

3

错误消息并没有用来告诉您哪个是 TupleN,尽管我认为这在某些时候得到了改进。不匹配发生在元组和 n 个参数之间。或不。

修复在2.9.2 中。我注意到您的 .sbt 使用 2.9.1 scalaquery,以防万一。scala-tools.org 不是已经过时了吗?抱歉帮了半忙。

作为一个非用户,看起来 Projection2 不是你想要的元组,尽管它是一个产品:

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

回复:

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
于 2012-12-14T20:53:58.333 回答