![](/img/trans.png)
[英]How To Delete an Object With Persistent/Non-Persistent Collection Field That is null?
[英]Is there a way to have a non-persistent field in GAE/J using JDO?
我打算让问题不再成为孩子,因为我必须独立地操作它,并且我不想保留问题字段,我想通过手动检索问题来填补问题。 这是代码。
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
@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)。
添加@NotPersistent
可能会有所帮助。
GAE / J文档完全具有误导性; 他们建议您在每个字段上都需要@Persistent
,这是完全错误的。 所有字段都有一个默认的持久标志...默认情况下,诸如String
,基元, Collection
, List
, Set
, Map
都是持久的,因此不需要@Persistent
。 关于Google的观点已经有好几次了,但是文档中仍然有这个观点。
如果您想根据JDO规范获得清晰的信息,请使用DataNucleus文档
添加“瞬态”可能也有帮助
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.