Skip to content

Instantly share code, notes, and snippets.

@jmaicher
Last active December 27, 2015 16:49
Show Gist options
  • Save jmaicher/7357429 to your computer and use it in GitHub Desktop.
Save jmaicher/7357429 to your computer and use it in GitHub Desktop.
Problem with play 2.2.1 and play-slick 0.5.0.8 when using the cake pattern as seen in the computer-database sample.
package lib.data
import play.api.db.slick.Config.driver.simple._
// Inspired by: http://bit.ly/HL0y7u
private[data] trait DAO extends ReviewersComponent with ProposalsComponent with ValuationsComponent {
val Reviewers = new Reviewers
val Proposals = new Proposals
val Valuations = new Valuations
}
trait ReviewersComponent { self: ValuationsComponent =>
val Reviewers: Reviewers
class Reviewers extends Table[(Int, String, String)]("Reviewers") {
def id = column[Int]("id", O.PrimaryKey)
def firstname = column[String]("firstname")
def lastname = column[String]("lastname")
def * = id ~ firstname ~ lastname
def valuations = Valuations.filter(_.reviewerId === id)
val byId = createFinderBy(_.id)
}
}
trait ProposalsComponent { self: ValuationsComponent =>
val Proposals: Proposals
class Proposals extends Table[(Int, String)]("Proposal") {
def id = column[Int]("id", O.PrimaryKey)
def title = column[String]("title")
def * = id ~ title
def valuations = Valuations.filter(_.proposalId === id)
val byId = createFinderBy(_.id)
}
}
trait ValuationsComponent { self: ReviewersComponent with ProposalsComponent =>
val Valuations: Valuations
class Valuations extends Table[(Int, Int, Int, Boolean)]("Valuations") {
def reviewerId = column[Int]("reviewer_id")
def proposalId = column[Int]("proposal_id")
def value = column[Int]("value")
def assigned = column[Boolean]("assigned")
def pk = primaryKey("reviewer_id_and_proposal_id", (reviewerId, proposalId))
def reviewer = foreignKey("reviewer_fk", reviewerId, Reviewers)(_.id)
def proposal = foreignKey("proposal_fk", proposalId, Proposals)(_.id)
def * = reviewerId ~ proposalId ~ value ~ assigned
}
}
object Reviewers extends DAO {
def findById(id: Int)(implicit s: Session) {
Reviewers.byId(id).firstOption
}
def insert(r: (Int, String, String))(implicit s: Session) {
Reviewers.insert(r)
}
}
object Proposals extends DAO {}
object Valuations extends DAO {}
package lib.data
import org.scalatest._
import play.api.test._
import play.api.test.Helpers._
import play.api.db.slick.DB
import slick.session.Session
import play.api.Play.current
class DatabaseSpec extends FlatSpec with Matchers {
"Reviewers model" should "be retrieved by id" in {
running(FakeApplication(additionalConfiguration = inMemoryDatabase(options=Map("MODE" -> "MySQL")))) {
DB.withSession { implicit s: Session =>
val reviewer = (23, "John", "Wayne")
Reviewers.insert(reviewer)
assert(Some(reviewer) === Reviewers.findById(23))
}
}
}
}
$ play test
[warn] application - Found a Slick table: lib.data.ReviewersComponent$Reviewers, but it does not have a constructor without arguments. Cannot create DDL for this class
[warn] application - Found a Slick table: lib.data.ValuationsComponent$Valuations, but it does not have a constructor without arguments. Cannot create DDL for this class
[warn] application - Found a Slick table: lib.data.ProposalsComponent$Proposals, but it does not have a constructor without arguments. Cannot create DDL for this class
- should be retrieved by id *** FAILED ***
org.h2.jdbc.JdbcSQLException: Table "Reviewers" not found; SQL statement:
INSERT INTO "Reviewers" ("id","firstname","lastname") VALUES (?,?,?) [42102-172]
at org.h2.message.DbException.getJdbcSQLException(DbException.java:329)
at org.h2.message.DbException.get(DbException.java:169)
at org.h2.message.DbException.get(DbException.java:146)
at org.h2.command.Parser.readTableOrView(Parser.java:4824)
at org.h2.command.Parser.readTableOrView(Parser.java:4802)
at org.h2.command.Parser.parseInsert(Parser.java:966)
at org.h2.command.Parser.parsePrepared(Parser.java:375)
at org.h2.command.Parser.parse(Parser.java:279)
at org.h2.command.Parser.parse(Parser.java:251)
at org.h2.command.Parser.prepareCommand(Parser.java:218)
...
Run completed in 8 seconds, 476 milliseconds.
Total number of tests run: 1
Suites: completed 1, aborted 0
Tests: succeeded 0, failed 1, canceled 0, ignored 0, pending 0
*** 1 TEST FAILED ***
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment