【问题标题】:Play framework: Slick does not know how to map the given types播放框架:Slick 不知道如何映射给定的类型
【发布时间】:2014-08-17 20:55:43
【问题描述】:

我正在尝试在播放框架中使用 slick,但即使是最简单的示例也很困难。

这是我的代码:

case class Account (
  id: Int,
  email: String,
  password: String,
  permission: String
)

class Accounts(tag: Tag) extends Table[Account](tag, "account") {
  def id = column[Int]("id")
  def email = column[String]("email")
  def password = column[String]("password")
  def permission = column[String]("permission")

  def * = (id, email, password, permission)
}

编译时出现以下错误:

play.PlayExceptions$CompilationException: Compilation error[No matching Shape found.
Slick does not know how to map the given types.
Possible causes: T in Table[T] does not match your * projection. Or you use an unsupported type in a Query (e.g. scala List).
  Required level: scala.slick.lifted.ShapeLevel.Flat
     Source type: (scala.slick.lifted.Column[Int], scala.slick.lifted.Column[String], scala.slick.lifted.Column[String], scala.slick.lifted.Column[String])
   Unpacked type: models.Account
     Packed type: Any
]

谁能告诉我这里是否有问题?

谢谢

更多细节:

  • Scala 2.10
  • 光滑 2.0.2
  • Play-slick 0.6.0.1
  • 播放框架 2.3.1

【问题讨论】:

    标签: scala playframework playframework-2.0 slick play-slick


    【解决方案1】:

    我找到了问题。我有一个冲突的伴随对象

    如果你有一个伴生对象,你需要为你的 * 投影使用稍微不同的语法:

    def * = (id, email, password, permission) <> ((Account.apply _).tupled, Account.unapply)
    

    【讨论】:

    • 我使用的是相同的语法,但它不适合我。不确定我是否遗漏了什么。我确实有一些时间戳字段,也许我缺少某种映射?
    【解决方案2】:

    根据http://slick.typesafe.com/doc/2.0.2/schemas.html,我觉得你的“*”投影方式应该是这样的:

    def * = (id, email, password, permission) <> (Account.tupled, Account.unapply)
    

    【讨论】:

    • 谢谢帕维尔。我也试过了,但我得到了这个错误:value tupled is not a member of object models.Account
    猜你喜欢
    • 1970-01-01
    • 2019-08-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-07-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多