【问题标题】:Google app engine data query returns 0 results谷歌应用引擎数据查询返回 0 个结果
【发布时间】:2016-07-31 19:26:42
【问题描述】:

我正在尝试使用带有 objectify 的谷歌应用引擎登录,但由于谷歌用户对象没有足够的信息,我创建了一个看起来像这样的本地实体:

@Cache
@Entity
public abstract class UserData extends RoleUser implements UserDetails {

    protected String firstName;
    protected String middleName;
    protected String lastName;


    protected boolean enabled;
    protected String phoneNumber;

    @Index
    protected String email;

    @Index
    protected String userName;

我有一个像这样的 GoogleUser 的子类:

@Subclass
public class GoogleUser extends UserData {

    private String googleUserId;
    private String authDomain;

最后,我运行查询是否为特定电子邮件创建了我的自定义实体,如下所示:

public boolean isNewUser(String email){
    int count = ofy().load().type(GoogleUser.class).filter("userName =", email).count();
    logger.debug("Total accounts for email: |" + email + "| \t Count: " + count);
    return count == 0;
} 

我遇到的问题是,即使我在本地 appengine 服务器上通过管理员查看数据存储区时看到了实体,查询也会返回 0 个结果。我已经走到了尽头,所以我将不胜感激。

【问题讨论】:

  • 你排除了eventual consistency吗?
  • @tx802 是的,我认为这不是复制问题,因为我重新启动了服务器,并且我看到该字段已在管理员中建立索引。我假设一旦它出现在管理员中,它就可以查询了,但我可能错了

标签: java google-app-engine objectify


【解决方案1】:

objectify 默认不索引子类。您必须为每个子类显式启用此功能,如下所示:

@Subclass(index=true)
public class GoogleUser extends UserData {

    private String googleUserId;
    private String authDomain;

请注意,如果您更改了类的多态层次结构,则需要重新保存实体才能使索引正常工作。

小提示:过滤器中没有运算符意味着 == 你的查询可以这样写

int count = ofy().load().type(GoogleUser.class).filter("userName", email).list();

【讨论】:

  • 我现在可以吻你。啊。我什至尝试为每个创建一个手动索引。我刚刚删除了所有实体并重试了它,效果很好。非常感谢,感谢您的提示!
【解决方案2】:

我想知道

.filter("userName =", email)

应该是

.filter("email =", email)

【讨论】:

  • 我实际上都试过了,对于谷歌帐户,用户名是电子邮件,我已经用电子邮件填写了这两个字段。 2016-07-31 15:56:39 调试 UserDao:54 - 电子邮件帐户总数:|test@example.com|计数:0
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-11-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多