我在我的play框架应用程序中使用Slick(Scalaquery)。根据{{3}} - 我可以为要插入的列定义投影。 (我正在定义此投影,因为我的索引是一个自动递增列。)但是,当我在插入中使用此投影时,我收到类型错误说:
[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]
有人可以通过指出我的插页有什么问题来帮助我吗?
答案 0 :(得分:1)
Scala 2.9不支持SLICK(Play使用)。所有“正确的”SLICK构建(在scala.slick名称空间和新的前端)都需要Scala 2.10.0-M4或-M5。 Scala 2.9上最新支持的版本是ScalaQuery 0.10.0-M1。
根据您在代码段中使用的功能判断,一切都应该与ScalaQuery 0.10.0-M1甚至0.9相同(除了不同的导入)。