2016-06-16 13 views
1

は、私は私のデシベルに製品を挿入しようとしないんだけど、実際には、私は私のモデルがどのように見えるん何もスリックは挿入しませんが、エラー

挿入:テーブル定義

case class Product(id: Option[Int], name: String, description: String, style: String, price: Int, cat_id: Int, size_id: Int, brand_id: Int) 

DAOで
class ProductsTable(tag: Tag) extends Table[Product](tag, "PRODUCTS") { 
    def id = column[Int]("PRODUCT_ID", O.PrimaryKey, O.AutoInc) 
    def title = column[String]("NAME") 
    def description = column[String]("DESCRIPTION") 
    def style = column[String]("STYLE") 
    def price = column[Int]("PRICE") 
    def category_id = column[Int]("CATEGORY_ID") 
    def size_id = column[Int]("SIZE_ID") 
    def brand_id = column[Int]("BRAND_ID") 
    def category = foreignKey("CAT_FK", category_id, cat.Categories)(_.cat_id, onUpdate=ForeignKeyAction.NoAction, onDelete=ForeignKeyAction.Cascade) 
    def size = foreignKey("SIZE_FK", size_id, sizes.Sizes)(_.size_id, onUpdate=ForeignKeyAction.NoAction, onDelete=ForeignKeyAction.Cascade) 
    def brand = foreignKey("BRAND_FK", brand_id, brands.Brands)(_.brand_id, onUpdate=ForeignKeyAction.NoAction, onDelete=ForeignKeyAction.Cascade) 
    def * = (id.?, title, description, style, price, category_id, size_id, brand_id) <>(Product.tupled, Product.unapply _) 
} 

Insertメソッド:

def insert(product: Product): Future[Unit] = db.run(Products += product).map { _ =>() } 

およびコントローラ:

def newproduct = Action { implicit request => 
    val product: models.Product = productForm.bindFromRequest().get 
    productDAO.insert(product) 
    Redirect(routes.ProductController.listproducts()) 
} 

答えて

1

今後、あなたはproductDAOから返されますか?これは非同期呼び出しなので、あなたが開始したスレッドで何も起こりません。将来に何が起こったのかを知るには、何らかの行動を取らなければなりません。

def newproduct = Action { implicit request => 
    val product: models.Product = productForm.bindFromRequest().get 
    import scala.concurrent.duration._ 
    Try(Await.result(productDAO.insert(product), 10 seconds)) match { 
    case Success(_) => 
     Redirect(routes.ProductController.listproducts()) 
    case Failure(e) => 
     log.error(e) // some logging 
     Failure(500) // some failure 
    } 
} 
:あなたのWebライブラリーは、あなたが答えを待つ必要があるかもしれません非同期でない場合

def newproduct = Action { implicit request => 
    val product: models.Product = productForm.bindFromRequest().get 
    productDAO.insert(product).andThen { 
    case Success(_) => 
     Redirect(routes.ProductController.listproducts()) 
    case Failure(e) => 
     log.error(e) // some logging 
     Failure(500) // some failure 
    } 
} 

:あなたはこのように仕上げることができるはず非同期(async)あなたのWebライブラリがある場合

関連する問題