Java 为什么核心数据存储类型的数组内容不存储在app engine中?

Java 为什么核心数据存储类型的数组内容不存储在app engine中?,java,google-app-engine,google-cloud-datastore,Java,Google App Engine,Google Cloud Datastore,我有以下问题: java对象包含两个核心数据存储类型的数组:com.google.appengine.api.datastore.Text和java.util.Date,外加一个int,用于存储数组和一些其他字段中当前填充的位置 我相信文档中指出,在类和字段注释下,核心数据类型的数组应该是可以的 使用名为updateAnswer的方法更新对象。调用此方法时,对象确实会更新,int会正确递增并存储,但数组只存储null 如果有人能指出我的错误所在,我将不胜感激 为完整起见,以下是对象及其父对象:

我有以下问题:

java对象包含两个核心数据存储类型的数组:com.google.appengine.api.datastore.Text和java.util.Date,外加一个int,用于存储数组和一些其他字段中当前填充的位置

我相信文档中指出,在类和字段注释下,核心数据类型的数组应该是可以的

使用名为updateAnswer的方法更新对象。调用此方法时,对象确实会更新,int会正确递增并存储,但数组只存储null

如果有人能指出我的错误所在,我将不胜感激

为完整起见,以下是对象及其父对象:

@PersistenceCapable
public class TextualAnswer extends Answer {

    @Persistent
    private Text textAnswer;

    @Persistent
    private Date date;

    @Persistent
    private int pos;

    @Persistent
    private Text texts[];

    @Persistent
    private Date dates[];

    public TextualAnswer(Key question, Key user, Date date) {
        super(question, user, 0);
        this.textAnswer = null;
        this.date = date;
        pos = 0;
        texts = new Text[20];
        dates = new Date[20];
    }

    public String getTextAnswer() {
        return (textAnswer != null ? textAnswer.getValue() : null);
    }

    public Date getDate() {
        return date;
    }

    public void updateAnswer(String textAnswer, Date date) {
        if (texts.length == pos) { // expand?
            Text ttemp[] = texts;
            texts = new Text[pos * 2];
            System.arraycopy(ttemp, 0, texts, 0, pos);

            Date dtemp[] = dates;
            dates = new Date[pos * 2];
            System.arraycopy(dtemp, 0, dates, 0, pos);
        }
        texts[pos] = this.textAnswer;
        dates[pos] = this.date;
        pos++;

        this.textAnswer = (textAnswer != null ? new Text(textAnswer) : null);
        this.date = date;
    }
}
家长:

@PersistenceCapable
@Inheritance(strategy = InheritanceStrategy.SUBCLASS_TABLE)
public abstract class Answer {
    @PrimaryKey
    @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
    private Key key;

    @Persistent
    private Key question;

    @Persistent
     private Key user;

    @Persistent
    private double score;

    @Persistent
    private boolean last;

    @Persistent
    private Text comment;

    public Answer(Key question, Key user, double score) {
        this.question = question;
        this.user = user;
        this.score = score;
        last = false;
        comment = null;
    }

    public Key getKey() {
        return key;
    }

    public Key getQuestion() {
        return question;
    }

    public Key getUser() {
        return user;
    }

    public double getScore() {
        return score;
    }

    public boolean isLast() {
        return last;
    }

    public String getComment() {
        return comment != null ? comment.getValue() : null;
    }

    public void setScore(double score) {
        this.score = score;
    }

    public void setLast(boolean last) {
        this.last = last;
    }

    public void setComment(String comment) {
        this.comment = comment != null ? new Text(comment) : null;
    }
}
结束语。我意识到我可以用列表等来代替,如果我不明白这一点,那确实是我的备份计划。但是,我想知道为什么这不起作用,所以我希望有人建议我切换到对象而不是数组,并解释为什么数组不起作用;多谢各位


前阿尼莫,-Alexander Yngling

所以,经过一段时间的睡眠,我突然想到。。。这是一个数组索引。我正在使用JDO。我是个白痴

我想删除这个问题,但万一有人搜索这个问题,问题是:

JDO无法知道数组索引已更新,因此您必须再次设置该字段,或使用以下命令通知JDO更新数据库:

JDOHelper.makeDirty(obj, "fieldName");