无法使用物化获取保存的实体 [英] Unable to get saved entity using objectify

查看:96
本文介绍了无法使用物化获取保存的实体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法使用Objectify获得可靠的实体。

看起来缓存已损坏。奇怪的是 - 我可以通过管理控制台数据存储查看器正确看到保存的实体。我还编写了一个小程序来查看使用RemoteApi的实体,我可以正确地看到保存的值。

当我使用servlet或云端点rest api连续查询实体时 - 我的连续查询给出了不同的结果,并且它看起来像数据存储区/缓存中的某个

我的实体看起来像这样。

  class ContentEntity {
@Id Long id;
String html;
@Index字符串标签;
布尔publish;
}

我将它保存为这样。

  ContentEntity entity = ofy()。load.type(ContentEntity.class)
.filter(tag,my tag)。first()。得到();

if(null == entity)
entity = new ContentEntity();

entity.html =我的html;
entity.tag =我的标签;
entity.publish = true;

ofy()。save.entity(entity).now();

我像这样检索它。

<$ p $(p> ContentEntity entity = ofy()。load().type(ContentEntity.class)。
filter(tag,my tag)。first()。get();

会发生什么如下 -

1)让ContentEntity.html的初始值为值1

2)使用管理控制台数据存储区查看器保存新值 - 值2

我可以看到值2被正确保存。 (使用远程API也可以看到值2)

3)使用上面粘贴的检索代码通过servlet或rest api查看实体。我看到value 2

4)通过servlet或rest api再次查看实体。我看到价值1

5)再次查看。我看到价值2

它继续在价值1和价值2之间切换



这一切在我的工作很好开发环境,但不在appengine中。



看起来我正在做错事,并且没有正确处理最终的一致性。我总是希望得到一致的结果。如果我的查询速度稍慢,我不介意。我应该怎么办?



任何提示/建议/帮助将不胜感激。



p>

Sathya

解决方案

事实证明,这是因为我忘记了添加在物理化wiki页面中提到的web.xml中的物化过滤器



我在web.xml中添加了以下内容,问题解决了。

 <滤光器> 
< 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> b




>

I am unable to get my saved entity reliably using Objectify.

It looks like the cache is getting corrupted. The strange thing is - I can see the saved entity correctly though admin console datastore viewer. Also I wrote a small program to view the entity using RemoteApi and I can see the saved value correctly.

When I query the entity successively using a servlet or a cloud endpoint rest api - my successive queries are giving different results, and it looks like something in the datastore/cache is getting corrupted.

My entity looks like this.

class ContentEntity {
  @Id Long id;
  String html;
  @Index String tag;
  boolean publish;
}

I save it like 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 it like this.

ContentEntity entity = ofy().load().type(ContentEntity.class).
            filter("tag", "my tag").first().get();

What happens is as follows -

1) Let the intial value of ContentEntity.html be "value 1"
2) save a new value - "value 2"
3) using admin console datastore viewer I can see "value 2" is saved correctly. (using remote api also I can see "value 2")
3) View the entity through servlet or rest api using the retrieve code pasted above. I see "value 2"
4) View the entity again through servlet or rest api. I see "value 1"
5) View it again. I see "value 2"
it keeps switching between "value 1" and "value 2"

It all worked fine in my dev environment but not in appengine.

Looks like I am doing something wrong and not handling eventual consistency correctly. I always want strongly consistent results. I don't mind if my queries are little slower. What should I do ?

Any tips/suggestions/help would be much appreciated.

Regards,

Sathya

解决方案

It turns out this is because I had forgotten to add objectify filter in web.xml as mentioned in Objectify wiki page

I added the following in my web.xml and the problem was 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

这篇关于无法使用物化获取保存的实体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆