google app engine - Null value returned while finding entity by key in JPA -
i developing app engine backend android 2 entities: user , item in 1 many relationship. after inserting item entity, receive inserted entity in client app generated key of item converted string , stored in database.later, while trying retrieve same entity passing keystring backend , converting key, getting null entity.what reason?
code retrieve , delete item entity:
@apimethod(name = "removeitembyid") public item removeitembyid(@named("itemidstring") string idstring) { //getting key idstring.. key key=keyfactory.stringtokey(idstring); entitymanager mgr = getentitymanager(); try { //this line null value returned... item item = mgr.find(item.class, key); mgr.remove(item); mgr.gettransaction().commit(); } catch(exception e) { mgr.gettransaction().rollback(); return null; } { mgr.close(); } return new item(); }
item entity:
@entity public class item { @id @generatedvalue(strategy = generationtype.identity) private key itemid; private string itemname; @manytoone(fetch=fetchtype.lazy) @joincolumn(name="owner_id") public user owner; ////getters , setters...... }
user entity:
@entity public class user { @id private string id; private string username; @onetomany(targetentity=com.example.xyz.item.class, mappedby="owner",cascade=cascadetype.all) private arraylist<item> items; //getters , setters... }
Comments
Post a Comment