java - Loaded Entity has parent but has no @Parent -
i have following schema, using objectify
@entity public class book{ @id private long id; private key<page> pages; … } @entity public class page{ @id private string id; … public page(book book,int pagenumber){ this.id = book.getid()+””+pagenumber; … } }
i getting complaint
com.googlecode.objectify.loadexception: error loading book(1401058017250)/page("14010580172505639445604728832"): loaded entity has parent com.company.api.db.page has no @parent
caused by: java.lang.illegalstateexception: loaded entity has parent com.company.api.db.page has no @parent
i coming eclipse , datanucleus , in framework code was
@entity public class book{ @id private long id; private list<page> pages; … } @entity public class page{ @id private key key; … public page(book book,int pagenumber){ this.key = createkey(book.getid(),pagenumber); … } private key createkey(long bookid, long pagenumber) { key bookkey = keyfactory.createkey(book.class.getsimplename(), bookid); key key = keyfactory.createkey(bookkey, page.class.getsimplename(), bookid + "" + pagenumber); return key; } }
whether best code or not, used work. anyway, migrating objectify , android studio. how rewrite schema stop getting error? if know answer, please copy , paste code snippet , make appropriate edits.
in old code, you're marking bookkey parent entity. in new code, need have:
@parent key<book> parentbook;
your new classes should be:
@entity public class book{ @id private long id; private list<key<page>> pages; … } @entity public class page{ @id private string id; @parent key<book> parentbook; … public page(long bookid, int pagenumber){ this.id = bookid + ”” +pagenumber; this.parentbook = key.create(book.class, bookid); … } }
read more keys , objectify here: https://code.google.com/p/objectify-appengine/wiki/concepts#keys
Comments
Post a Comment