学习GAE我遇到了一些问题。我想在数据库中保存我的用户的联系人列表。我使用addUser()添加新用户,它的工作原理。但是当我刷新页面时,列表为空(不为空)。在GAE“数据存储查看器”中,“列表”字段为空,但在应用程序中它存在。
@PersistenceCapable(identityType = IdentityType.APPLICATION, detachable="true")
public class ContactList implements IUserList {
@PrimaryKey
@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
private Key key;
@Persistent
protected List<Key> list;
@Persistent(mappedBy = "contactList")
private User user;
public Key getKey(){
return this.key;
}
public User getUser() {
return user;
}
public ContactList(User user) {
this.list = new ArrayList<Key>(); //this line invoice one only
}
@Override
public Boolean addUser(User user) {
if(this.list.contains(user.getKey())){
return false;
}else{
this.list.add(user.getKey());
return true;
}
}
@Override
public boolean containsKey(Long id) {
return false; //this.list.containsKey(id);
}
@Override
public User get(Long id) {
return null;// this.list.get(id);
}
@Override
public void removeUser(User user) {
this.list.remove(user.getKey());
}
@Override
public int size() {
return this.list.size();
}
@Override
public List<User> users() {
ArrayList<User> users = new ArrayList<User>();
for(Key key : this.list) {
User user = UserManager.getInstance().getUser(key);
users.add(user);
}
return users;
}
@Override
public void addEvent(IEvent event) {
for(User user : this.users()) {
user.addEvent(event);
}
}
@Override
public void clearEvents() {
}
@Override
public ArrayList<IEvent> getEvents() {
return null;
}
}
答案 0 :(得分:1)
您没有将数据保存到数据库中,因此您实际上正在执行ghost读取。
保存数据的方法:http://code.google.com/appengine/docs/java/datastore/creatinggettinganddeletingdata.html