Play Framework:在课堂上找不到@javax.persistence.Id字段

时间:2014-02-20 20:59:56

标签: java playframework annotations persistence

我有这个Play Model类,我试图修改它的对象,当我想保存它时,我得到以下异常:

java.lang.RuntimeException: No @javax.persistence.Id field found in class [class models.Contact]
at play.db.ebean.Model._idAccessors(Model.java:39)
at play.db.ebean.Model._getId(Model.java:52)

班级:

@Entity
public class Contact extends Model implements Person {//, Comparable<Contact>{

private Long id;

private Client client;

@Required
private String email;

private String profil_picture;

private Boolean active = new Boolean(true);

private Boolean favorite = new Boolean(false);

@Transient
private Boolean profile_pic_url_init = new Boolean(false);
@Id 
@GeneratedValue
public Long getId() {
    return id;
}
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name="client_id") 
public Client getClient(){
    return client;
}
public void setClient(Client client){
    this.client= client;
}
@Column
public Boolean getFavorite() {
    return favorite;
}
public void setFavorite(Boolean is_favorite) {
    this.favorite = is_favorite;
}
....
}

调用save()方法的代码:

        List<Contact> contacts_list = current_client.getContacts();
        for (Contact c : contacts_list) {
            c.setFavorite(false);
            c.save();
        }

该类实际上有一个@Id注释,因此任何猜测为什么这不起作用?我尝试在谷歌上查找,但无法找到很多关于此错误的信息。提前谢谢!

1 个答案:

答案 0 :(得分:3)

@Id注释移至id字段而不是其getter。