سؤال

I have to develop a web application for school, but i have the following problem: i have an object which has a few attributes, one of them is an arraylist with custom objects. then i use objectify to put the object in the datastore, but when i check on the gae dashboard datastore viewer, it has all the attributes but not the arraylist.

To give a better view of how it works: this is the object containing the arraylist:

public class Competentie implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id Long id;
    private String competentie;
    List<Stelling> deStellingen = new ArrayList<Stelling>();

    public Competentie(String c){
        competentie = c;
    }

    public Competentie(){}

    public String getCompetentie(){
        return competentie;
    }

    public void setCompetentie(String c){
        competentie = c;
    }

    public void voegStellingToe(Stelling s){
        deStellingen.add(s);
    }

    public List<Stelling> getStellingen(){
        return deStellingen;
    }
}

And here is how i put it in the datastore

public void createCompetentie(String comp){
   Competentie c = new Competentie(comp);
   ofy.put(c);
}

Could someone help me out on this? And if someone needs more information just ask.

هل كانت مفيدة؟

المحلول

Look here on there wiki: https://code.google.com/p/objectify-appengine/wiki/Entities#Embedding

Did you use the @Embed on the Stelling class? That is the only thing I can think of. Also they have a list of things to keep in mind on embeded classes, they are: Some things to keep in mind:

This does not support two-dimensional structures of any kind. You cannot nest @Embed arrays/collections inside other @Embed arrays/collections. You cannot put arrays/collections of native types inside @Embed arrays/collections. You can, however, nest @Embed arrays/collections inside any number of @Embed classes. You should initialize collections. Null or empty collections are not written to the datastore and therefore get ignored during load. Furthermore, the concrete instance will be used as-is, allowing you to initialize collections with Comparators or other state.

You can also consider searlizing the deStellingen object if one of the above is true, but then you can't query on it. https://code.google.com/p/objectify-appengine/wiki/Entities#Serializing

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top