gpt4 book ai didi

java - Play Framework : No @javax. persistence.Id 字段在类中找到

转载 作者:行者123 更新时间:2023-12-01 23:11:22 26 4
gpt4 key购买 nike

我有一个 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)

类(class):

@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 注释,所以你猜为什么这不起作用?我尝试在谷歌上查找它,但找不到有关此错误的更多信息。提前致谢!

最佳答案

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

关于java - Play Framework : No @javax. persistence.Id 字段在类中找到,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21919470/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com