2015-02-10 38 views
1

我有我的超級抽象類:在Play中使用save()方法!與繼承(JPA)

​​

與其他兩個類擴展用戶:

客戶

@Entity 
@Table(name = "customers") 
public class Customer extends User{ 

    @Id 
    public int id; 
    public String role; 

    public Customer(String role){ 
     super(); 
     this.role = role; 
    } 
} 

賣家

@Entity 
@Table(name = "sellers") 
public class Seller extends User{ 

    @Id 
    @GeneratedValue 
    public int id; 
    public String role; // Seller 

    public Seller(String role){ 
     super(); 
     this.role = role; 
    } 
} 

我想能夠使用保存()方法在玩,所以我寫了這個:

public static Result saveCustomer(){ 
     Customer customer = Form.form(Customer.class).bindFromRequest().get(); 
     customer.save();   
     return ok(); 
    } 

但是,保存()沒有定義。

解決此問題的方法是什麼?

回答

1

其實...要得到entityManager在play 2.x你有一個幫手。

JPA.em().persist(object); 

你可以在link看到更多的信息。

+0

謝謝!我認爲你的鏈接不可用了... – Mornor 2015-02-11 15:11:34

+0

是...它si:P https://www.playframework.com/documentation/2.4.x/JavaJPA – 2015-02-11 15:16:20

+0

Oups,對不起,我的壞:(我檢查這個權利現在請 – Mornor 2015-02-11 16:04:07

0

save()方法是GenericModel的一部分,它屬於Play 1.x。因爲,您使用Play 2.x您應該使用JPA對象和entityManager.persist()方法。