google app engine - Unable to get saved entity using objectify -
i unable saved entity reliably using objectify.
it looks cache getting corrupted. strange thing - can see saved entity correctly though admin console datastore viewer. wrote small program view entity using remoteapi , can see saved value correctly.
when query entity successively using servlet or cloud endpoint rest api - successive queries giving different results, , looks in datastore/cache getting corrupted.
my entity looks this.
class contententity { @id long id; string html; @index string tag; boolean publish; }
i save this.
contententity entity = ofy().load.type(contententity.class) .filter("tag", "my tag").first().get(); if (null == entity) entity = new contententity(); entity.html = "my html"; entity.tag = "my tag"; entity.publish = true; ofy().save.entity(entity).now();
i retreive this.
contententity entity = ofy().load().type(contententity.class). filter("tag", "my tag").first().get();
what happens follows -
1) let intial value of contententity.html "value 1"
2) save new value - "value 2"
3) using admin console datastore viewer can see "value 2" saved correctly. (using remote api can see "value 2")
3) view entity through servlet or rest api using retrieve code pasted above. see "value 2"
4) view entity again through servlet or rest api. see "value 1"
5) view again. see "value 2"
keeps switching between "value 1" , "value 2"
it worked fine in dev environment not in appengine.
looks doing wrong , not handling eventual consistency correctly. want consistent results. don't mind if queries little slower. should ?
any tips/suggestions/help appreciated.
regards,
sathya
it turns out because had forgotten add objectify filter in web.xml mentioned in objectify wiki page
i added following in web.xml , problem solved.
<filter> <filter-name>objectifyfilter</filter-name> <filter-class>com.googlecode.objectify.objectifyfilter</filter-class> </filter> <filter-mapping> <filter-name>objectifyfilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping>
regards,
sathya
Comments
Post a Comment