0

我在我的游戏框架应用程序中使用 Slick (Scalaquery)。根据slick tutorial - 我可以为要插入的列定义投影。(我正在定义这个投影,因为我的索引是一个自动递增的列。)但是,当我在插入中使用这个投影时,我得到一个类型错误说:

[NoSuchMethodError: scala.Predef$.augmentString(Ljava/lang/String;)Ljava/lang/String;].

我的模型是这样定义的:

package models

import play.api.db._
import play.api.Play.current

import scala.slick.driver.PostgresDriver.simple._
import scala.slick.ql.{MappedTypeMapper}
import scala.slick.session.{Session, Database}

case class Book(name: String, filename: String)

object Book extends Table[(Long, String, String)]("book") {

  lazy val database = Database.forDataSource(DB.getDataSource())
  def id = column[Long]("id", O PrimaryKey, O AutoInc)
  def name = column[String]("name", O NotNull)
  def filename = column[String]("filename", O NotNull)
  def * = id ~ name ~ filename
  def withoutId = name ~ filename

  def findAll() : Seq[Book] = database.withSession { implicit db:Session =>
    (for(t <- this) yield t.name ~ t.filename).list.map(attrs => Book(attrs._1, attrs._2))
  }

  def create(book: Book): Unit = database.withSession { implicit db:Session =>
    this.withoutId insert(book.name, book.filename)
  }

}

这是堆栈跟踪:

! @6b1eg7f2d - Internal server error, for request [POST /addBook] ->

play.core.ActionInvoker$$anonfun$receive$1$$anon$1: Execution exception [[NoSuchMethodError: scala.Predef$.augmentString(Ljava/lang/String;)Ljava/lang/String;]]
    at play.core.ActionInvoker$$anonfun$receive$1.apply(Invoker.scala:134) [play_2.9.1-2.0.2.jar:2.0.2]
    at play.core.ActionInvoker$$anonfun$receive$1.apply(Invoker.scala:115) [play_2.9.1-2.0.2.jar:2.0.2]
    at akka.actor.Actor$class.apply(Actor.scala:318) [akka-actor-2.0.2.jar:2.0.2]
    at play.core.ActionInvoker.apply(Invoker.scala:113) [play_2.9.1-2.0.2.jar:2.0.2]
    at akka.actor.ActorCell.invoke(ActorCell.scala:626) [akka-actor-2.0.2.jar:2.0.2]
    at akka.dispatch.Mailbox.processMailbox(Mailbox.scala:197) [akka-actor-2.0.2.jar:2.0.2]
Caused by: java.lang.NoSuchMethodError: scala.Predef$.augmentString(Ljava/lang/String;)Ljava/lang/String;
    at scala.slick.driver.BasicSQLUtilsComponent$class.quoteIdentifier(BasicSQLUtilsComponent.scala:12) ~[slick_2.10.0-M4-0.10.0-M2.jar:0.10.0-M2]
    at scala.slick.driver.PostgresDriver$.quoteIdentifier(PostgresDriver.scala:69) ~[slick_2.10.0-M4-0.10.0-M2.jar:0.10.0-M2]
    at scala.slick.driver.BasicStatementBuilderComponent$InsertBuilder.appendNamedColumn(BasicStatementBuilderComponent.scala:400) ~[slick_2.10.0-M4-0.10.0-M2.jar:0.10.0-M2]
    at scala.slick.driver.BasicStatementBuilderComponent$InsertBuilder.scala$slick$driver$BasicStatementBuilderComponent$InsertBuilder$$f$1(BasicStatementBuilderComponent.scala:387) ~[slick_2.10.0-M4-0.10.0-M2.jar:0.10.0-M2]
    at scala.slick.driver.BasicStatementBuilderComponent$InsertBuilder$$anonfun$scala$slick$driver$BasicStatementBuilderComponent$InsertBuilder$$f$1$1.apply$mcVI$sp(BasicStatementBuilderComponent.scala:377) ~[slick_2.10.0-M4-0.10.0-M2.jar:0.10.0-M2]
    at scala.collection.immutable.Range.foreach$mVc$sp(Range.scala:75) ~[scala-library.jar:0.11.3]

有人可以通过指出我的插入有什么问题来帮助我吗?

4

1 回答 1

1

Scala 2.9(Play 使用的)不支持 SLICK。所有“正确”的 SLICK 构建(在 scala.slick 命名空间和新的前端)都需要 Scala 2.10.0-M4 或 -M5。Scala 2.9 上支持的最新版本是 ScalaQuery 0.10.0-M1。

从您在代码片段中使用的功能来看,ScalaQuery 0.10.0-M1 甚至 0.9 的所有内容都应该以相同的方式工作(除了不同的导入)。

于 2012-07-22T13:12:39.747 回答