2017-01-10 9 views
2

私は通常の

db.run(tableQ.result)であることを利用して "選択"

保護ヴァルtableQをやろうとしています:TableQuery [T] 私はそれをやっているように見える例では、私はエラーが表示されます:play.api.http.HttpErrorHandlerExceptions $$ anon $ 1:実行例外[[RuntimeException:java.lang.NoSuchMethodError:slick .driver.JdbcProfile $

私は、このコード行である必要があります。

Caused by: java.lang.NoSuchMethodError: slick.driver.JdbcProfile$API.streamableQueryActionExtensionMethods(Lslick/lifted/Query;)Lslick/profile/BasicActionComp$$$$6aa48549c0a7603df1fa229cf7177493$$$$sionMethodsImpl; 
     at models.daos.BaseDAO.getAll(BaseDAO.scala:62) 
     at controllers.CategoryController$$anonfun$list$1.apply(CategoryController.scala:28) 

def getAll : Future[Seq[A]] = { 
    db.run(tableQ.result) 
    } 

BaseDAO.scala

package models.daos 

import models.entities.{Supplier, BaseEntity, Category, Product} 
import models.persistence.SlickTables 
import models.persistence.SlickTables.{SuppliersTable, BaseTable, CategoriesTable, ProductsTable} 
import play.api.Play 
import play.api.db.slick.{DatabaseConfigProvider, HasDatabaseConfig} 
import slick.backend.DatabaseConfig 
import slick.driver.JdbcProfile 
import slick.lifted.{CanBeQueryCondition} 
import scala.concurrent.Future 
import play.api.libs.concurrent.Execution.Implicits.defaultContext 

trait AbstractBaseDAO[T,A] { 
    def insert(row : A): Future[Long] 
    def insert(rows : Seq[A]): Future[Seq[Long]] 
    def update(row : A): Future[Int] 
    def update(rows : Seq[A]): Future[Unit] 
    def findById(id : Long): Future[Option[A]] 
    def findByFilter[C : CanBeQueryCondition](f: (T) => C): Future[Seq[A]] 
    def deleteById(id : Long): Future[Int] 
    def deleteById(ids : Seq[Long]): Future[Int] 
    def deleteByFilter[C : CanBeQueryCondition](f: (T) => C): Future[Int] 
    def getAll() : Future[Seq[A]] 
} 


abstract class BaseDAO[T <: BaseTable[A], A <: BaseEntity]() extends AbstractBaseDAO[T,A] with HasDatabaseConfig[JdbcProfile] { 
    protected lazy val dbConfig: DatabaseConfig[JdbcProfile] = DatabaseConfigProvider.get[JdbcProfile](Play.current) 
    import dbConfig.driver.api._ 

    protected val tableQ: TableQuery[T] 

    def insert(row : A): Future[Long] ={ 
    insert(Seq(row)).map(_.head) 
    } 

    def insert(rows : Seq[A]): Future[Seq[Long]] ={ 
    db.run(tableQ returning tableQ.map(_.id) ++= rows.filter(_.isValid)) 
    } 

    def update(row : A): Future[Int] = { 
    if (row.isValid) 
     db.run(tableQ.filter(_.id === row.id).update(row)) 
    else 
     Future{0} 
    } 

    def update(rows : Seq[A]): Future[Unit] = { 
    db.run(DBIO.seq((rows.filter(_.isValid).map(r => tableQ.filter(_.id === r.id).update(r))): _*)) 
    } 

    def findById(id : Long): Future[Option[A]] = { 
    db.run(tableQ.filter(_.id === id).result.headOption) 
    } 

    def findByFilter[C : CanBeQueryCondition](f: (T) => C): Future[Seq[A]] = { 
    db.run(tableQ.withFilter(f).result) 
    } 

    def getAll : Future[Seq[A]] = { 
    db.run(tableQ.result) 
    } 

    def deleteById(id : Long): Future[Int] = { 
    deleteById(Seq(id)) 
    } 

    def deleteById(ids : Seq[Long]): Future[Int] = { 
    db.run(tableQ.filter(_.id.inSet(ids)).delete) 
    } 

    def deleteByFilter[C : CanBeQueryCondition](f: (T) => C): Future[Int] = { 
    db.run(tableQ.withFilter(f).delete) 
    } 

} 

version := "0.0.1" 

lazy val root = (project in file(".")).enablePlugins(PlayScala) 

scalaVersion := "2.11.8" 

libraryDependencies ++= Seq(
    "com.typesafe.play" %% "play-slick" % "1.1.1", 
    "com.typesafe.play" %% "play-slick-evolutions" % "1.1.1", 
    evolutions, 
    "com.h2database" % "h2" % "1.4.191", 
    cache, 
    ws, 
    "org.scalatestplus.play" %% "scalatestplus-play" % "1.5.0-RC1" % Test 
) 

resolvers += "scalaz-bintray" at "http://dl.bintray.com/scalaz/releases" 

が./activatorの実行を使用してコンパイルbuild.sbt

+0

どのようにコードを作成/構築していますか?これはクラスパスの問題 – Edmondo1984

+0

のように見えるかもしれません。あるいは、異なる 'Scala'バージョン用にコンパイルされた' Slick'バージョンを使用していますか? –

+0

私はbuild.sbtを表示するように編集しました。コードをコンパイルするためにアクチベータを使用しています。ターゲットは/ tmp/project-targetへのリンクです.linuxのencryptfsを使用する際のバグのためです。 –

答えて

0

は、あなたが(これで私はわからないが、どのプレイをしてみてくださいでしたあなたが使用しているバージョン)?

libraryDependencies ++= Seq(
    "com.typesafe.play" %% "play-slick" % "2.0.0" 
    "com.typesafe.play" %% "play-slick-evolutions" % "2.0.0" 
) 
+0

いいえ。これは、長いファイル名の問題に遭遇する前にうまくいきました。そして、私はまた、プレイフレームワークのルートファイルを変更しました。あなたが使用しているバージョンを再生する –

+0

ですか? –

+0

私はplay-slick 2.0.0にアップグレードしました。魔法使いはslick 3.1とplay 2.5.0を持っています。 –

関連する問題