2015-02-08 38 views
1

黑傢伙,PlayFramework不能.save() - 到數據庫

我想要一個簡單的例子,一些酒吧保存到我的數據的基礎上,...但我不明白爲什麼保存方法不起作用爲了我。我是新的玩家框架「家庭」,所以可能這是我失蹤的一件小事。

所以......

這裏是我的模型:

package models; 
import play.db.ebean.Model; 
import javax.persistence.Entity; 
import javax.persistence.Id; 



@Entity 
public class Bar { 

    @Id 
    public String Id; 

    public String name; 
} 

這裏是我的控制器:

package controllers; 

import models.Bar; 
import play.*; 
import play.data.Form; 
import play.mvc.*; 

import views.html.*; 

public class Application extends Controller { 

    public static Result index() { 
     return ok(index.render("Hello world")); 
    } 

    public static Result addBar(){ 

     Bar bar = Form.form(Bar.class).bindFromRequest().get(); 
     bar.save(); 


     return redirect(routes.Application.index()); 
    } 
} 

我的路線文件:

# Home page 
GET /       controllers.Application.index() 
POST /bars      controllers.Application.addBar() 

而且這是我的錯誤:

I get a : Compilation error 
That says: error: cannot find symbol 

[at line20]: bar.save(); 

我已經激活ebean和conf文件數據庫:

db.default.driver=org.h2.Driver 
db.default.url="jdbc:h2:mem:play" 
# db.default.user=sa 
# db.default.password="" 
... 
ebean.default="models.*" 

我已經清理的項目了幾次,仍然沒有工作... 能否請你告訴我缺少什麼?

非常感謝......

回答

0

你沒有擴展你的模型類

public class Bar extends Model 
相關問題