【发布时间】:2013-11-20 10:40:08
【问题描述】:
我正在尝试实现一个简单的 GAE 服务。特别是我有学生实体和类别实体。每个学生可以关联一个或多个类别。如何使用 Objectify 创建这种关系?谢谢
编辑:这是我的代码。有效吗?
@Entity
public class Studente {
static long nextID = 17;
public static Key<Studente> key(long id) {
return Key.create(Studente.class, id);
}
List<Key<Categoria>> categorie;
public Studente() {}
@Id Long id;
@Index String nome;
@Index String cognome;
@Index String username;
@Index String password;
public Studente(String nome, String cognome, String username, String password) {
this.nome=nome;
this.cognome=cognome;
this.username=username;
this.password=password;
categorie = new ArrayList<Key<Categoria>>();
}
public static long getNextID() {
return nextID;
}
public static void setNextID(long nextID) {
Studente.nextID = nextID;
}
public List<Key<Categoria>> getCategorie() {
return categorie;
}
public void setCategorie(List<Key<Categoria>> categorie) {
this.categorie = categorie;
}
public void addCategoria(Key<Categoria> k ){
categorie.add(k);
}
}
【问题讨论】:
标签: java google-app-engine google-cloud-datastore objectify