我想要我的类映射,包括漂亮的,所以我能坚持他们。 我的业务对象是这样定义的
case class Book(id : Option[Long], author : Author, title : String, readDate : Date, review : String){}
case class Author(id : Option[Long], name : String, surname : String) {}
然后我定义了作者的“表”类:
class Authors(tag : Tag) extends Table[Author](tag,"AUTHORS") {
def id = column[Option[Long]]("AUTHOR_ID", O.PrimaryKey, O.AutoInc)
def name = column[String]("NAME")
def surname = column[String]("SURNAME")
def * = (id, name, surname) <> ((Author.apply _).tupled , Author.unapply)
}
而对于书籍:
class Books (tag : Tag) extends Table[Book](tag, "BOOKS") {
implicit val authorMapper = MappedColumnType.base[Author, Long](_.id.get, AuthorDAO.DAO.findById(_))
def id = column[Option[Long]]("BOOK_ID", O.PrimaryKey, O.AutoInc)
def author = column[Author]("FK_AUTHOR")
def title = column[String]("TITLE")
def readDate = column[Date]("DATE")
def review = column[Option[String]]("REVIEW")
def * = (id, author, title, readDate, review) <> ((Book.apply _).tupled , Book.unapply)
}
但是,当我编译我得到这个错误
Error:(24, 51) 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.FlatShapeLevel
Source type: (scala.slick.lifted.Column[Option[Long]], scala.slick.lifted.Column[model.Author], scala.slick.lifted.Column[String], scala.slick.lifted.Column[java.sql.Date], scala.slick.lifted.Column[Option[String]])
Unpacked type: (Option[Long], model.Author, String, java.sql.Date, String)
Packed type: Any
def * = (id, author, title, readDate, review) <> ((Book.apply _).tupled , Book.unapply)
^
而且这一个:
Error:(24, 51) not enough arguments for method <>: (implicit evidence$2: scala.reflect.ClassTag[model.Book], implicit shape: scala.slick.lifted.Shape[_ <: scala.slick.lifted.FlatShapeLevel, (scala.slick.lifted.Column[Option[Long]], scala.slick.lifted.Column[model.Author], scala.slick.lifted.Column[String], scala.slick.lifted.Column[java.sql.Date], scala.slick.lifted.Column[Option[String]]), (Option[Long], model.Author, String, java.sql.Date, String), _])scala.slick.lifted.MappedProjection[model.Book,(Option[Long], model.Author, String, java.sql.Date, String)].
Unspecified value parameter shape.
def * = (id, author, title, readDate, review) <> ((Book.apply _).tupled , Book.unapply)
^
这里有什么错误? 什么是我没有得到有关华而不实? 先感谢您!