IllegalArgumentException:GAE中的偏移量不得超过1000

时间:2014-02-12 12:42:35

标签: google-app-engine objectify

我有这个简单的ednpoint方法:

@ApiMethod(name = "createCategory")
public RCategory createCategory(@Named("userHash")String userHash, @Nullable @Named("synchronously")Boolean synchronously, Category category) throws AccessForbiddenException, DuplicateEntityNameException, SubscriptionRequiredException {
    User user = OwlEndpoint.getUser(userHash);
    if (!user.hasSubscriptionActive()) throw new SubscriptionRequiredException();

    //Sprawdzam czy w profilu uzytkownika jest wiecej niz on sam (o ile w ogole ma profil)
    List<Long> usersInProfileIds = getUsersInProfilesIds(user);

    if (ofy().load().type(Category.class).filter("creatorId in", usersInProfileIds).filter("name", category.getName()).count() > 0) throw new DuplicateEntityNameException();
    category.setCreatorId(user.getId());

    if (synchronously != null && synchronously) ofy().save().entity(category).now();
    else ofy().save().entity(category);

    return new RCategory(category, user.getId());
}

它在DEV服务器上工作正常,但在上传到GAE后它开始失败。我在日志中找到了这个,但这对我来说没有意义:

    Request URL: https://myapp.appspot.com/_ah/api/owlendpoint/v1/createCategory/0A71A4A761C2B0C49BE3CE4ED19E78E93911DAE1E53732BE5635B29F923DBBFD5C54DEBE7F80831364D8255861D46878ADB657D0DDA95EEAF19956A6C5967CADF903543D1DA577677FEAEC70F0019B055C4CBA168A4A188D41393A9BF08834A92F8BB13D5E03F7F901C1281878BE8B79
    Method: myappendpoint.createCategory
    Error Code: 400
    Reason: badRequest    
    Message: java.lang.IllegalArgumentException: offset may not be above 1000

1 个答案:

答案 0 :(得分:0)

我制作了这个方法:

@SuppressWarnings("rawtypes")
public static boolean hasItems(Query query) {
    Iterator it = query.iterator();
    return it.hasNext();
}

我正在使用它来定义,如果查询中至少有一个元素而不使用count()。还是想知道如何使用count()以及如何使用...