Objectify - 如何在使用 Long 时获取实体的自动生成 ID?
Objectify - How to get auto generated id of the entity, when Long is used?
如何在使用 Long 时获取实体的自动生成 ID?我有一个像下面这样的实体
@Entity
public class DailyChallenge {
@Id
public Long id;
public String title;
}
这里的id是自动生成的。我怎样才能得到这个 ID?
将实体保存到 objectify 后,将在实体上设置 ID。
DailyChallenge de = new DailyChallenge();
de.title = "some title";
ObjectifyService.ofy().save().entities(de).now();
System.out.println(de.id); // This is non null now.
如何在使用 Long 时获取实体的自动生成 ID?我有一个像下面这样的实体
@Entity
public class DailyChallenge {
@Id
public Long id;
public String title;
}
这里的id是自动生成的。我怎样才能得到这个 ID?
将实体保存到 objectify 后,将在实体上设置 ID。
DailyChallenge de = new DailyChallenge();
de.title = "some title";
ObjectifyService.ofy().save().entities(de).now();
System.out.println(de.id); // This is non null now.