gpt4 book ai didi

java - Google 应用引擎数据查询返回 0 个结果

转载 作者:行者123 更新时间:2023-12-02 03:27:08 25 4
gpt4 key购买 nike

我正在尝试使用带有 objectify 的 Google 应用引擎登录,但由于 Google User 对象没有足够的信息,我创建了一个如下所示的本地实体:

@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 结果。我已经束手无策了,所以我将不胜感激。

最佳答案

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();

关于java - Google 应用引擎数据查询返回 0 个结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38687652/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com