有没有一种方法可以使用JDO在GAE/J中具有非持久字段? [英] Is there a way to have a non-persistent field in GAE/J using JDO?

查看:73
本文介绍了有没有一种方法可以使用JDO在GAE/J中具有非持久字段?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我打算让问题不再成为孩子,因为我必须独立地操纵它,并且我不想保留问题字段,我想通过手动检索问题来填补问题.这是代码.

I intend questions not to be a child since I had to manipulate it independently, and I don't want to persist the questions field, I would to fill it up by retrieving the questions manually. Here is the code.

Questionnaire.java

Questionnaire.java

@PersistenceCapable(identityType = IdentityType.APPLICATION)
public class Questionnaire{
    //supposedly non-persistent
    public List<Question> questions  = new ArrayList<Question>();

    @PrimaryKey
    @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
    public Long questionnaireID;

    @Persistent
    public String title;

    @Persistent
    private int items;

    @Persistent
    public String description;

Question.java

Question.java

@PersistenceCapable(identityType = IdentityType.APPLICATION)
public class Question{
    //non-persistent as well
    public ArrayList<Choice> choiceList = new ArrayList<Choice>();

    @PrimaryKey
    @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
    public Long questionID;

    @Persistent 
    public String text;

    @Persistent 
    public long questionnaireID;


    public Question(){

    }

会吐出这个错误:

org.datanucleus.store.appengine.MetaDataValidator $ DatastoreMetaDataException:com.ivanceras.server.Question.questionID的元数据出错:不能具有java.lang.Long主键,并且不能成为子对象(所有者字段是com.ivanceras.server.Questionnaire.questions).

org.datanucleus.store.appengine.MetaDataValidator$DatastoreMetaDataException: Error in meta-data for com.ivanceras.server.Question.questionID: Cannot have a java.lang.Long primary key and be a child object (owning field is com.ivanceras.server.Questionnaire.questions).

推荐答案

添加@NotPersistent可能会有所帮助.

Adding a @NotPersistent might help.

GAE/J文档完全具有误导性;他们建议您在每个字段上都需要@Persistent,这是完全错误的.所有字段均具有默认的持久性标志...默认情况下,诸如String,基元,CollectionListSetMap之类的东西都是持久性的,因此不需要这些上的@Persistent.对于Google来说,这已经有好几次了,但是文档仍然对此有所说明.

The GAE/J docs are totally misleading; they suggest that you need @Persistent on every field and that is totally wrong. All fields have a default persistent flag ... things like String, primitives, Collection, List, Set, Map are by default persistent so no need for @Persistent on those. This point has been made to Google several times yet the docs still have this.

如果您希望根据JDO规范获得清晰的信息,请使用DataNucleus文档

Use the DataNucleus docs if you want clear information as per the JDO spec

这篇关于有没有一种方法可以使用JDO在GAE/J中具有非持久字段?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆