views:

78

answers:

1

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

@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(){

    }

would spit out this error:

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).

A: 

Adding a @NotPersistent might help.

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.

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

DataNucleus