【问题标题】:IN criteria only works with single value datastore query - Google app engineIN 条件仅适用于单值数据存储查询 - Google 应用引擎
【发布时间】:2014-04-04 06:37:02
【问题描述】:

我想在我的应用引擎数据存储应用引擎上执行IN 查询。在这里我遇到了奇怪的问题。问题是,当我将单个值传递给IN 标准时,它会返回正确的记录,但是当我将多个值传递给IN 标准时,它会返回null 响应。如果我在服务器上执行相同的查询,那么它会返回正确的输出。我不知道我的代码有什么问题。我在我的 android 客户端中使用 endpoint 类,并且我正在将值从 android 客户端传递到应用程序引擎后端。请帮我解决这个问题。谢谢。

更新:

我更改了我的代码,如下所示,现在我将 ArrayList 作为参数传递并使其正常工作。

代码:

    @SuppressWarnings({ "unchecked", "unused" })
            @ApiMethod(name = "getUserFavouriteFeed", httpMethod = HttpMethod.GET, path = "userfeedmasterendpoint/userName_fk1")
            public CollectionResponse<tableFresopnce> getUserFavouriteFeed(
                    @Named("uname") ArrayList<String> uname,
                    @Nullable @Named("cursor") String cursorString,
                    @Nullable @Named("limit") Integer limit) {

                EntityManager mgr = null;
                Cursor cursor = null;
                List<UserFeedMaster> execute = null;

                try {
                    mgr = getEntityManager(); 
                    Query query = mgr
                            .createQuery("select f from tableF f where f.isDeleted=:delStatus and f.userName in (:uname)"); 


                    query.setParameter("uname", uname); 

                    query.setParameter("delStatus", false);

                    if (cursorString != null && cursorString != "") {
                        cursor = Cursor.fromWebSafeString(cursorString);
                        query.setHint(JPACursorHelper.CURSOR_HINT, cursor);
                    }

                    if (limit != null) {
                        query.setFirstResult(0);
                        query.setMaxResults(limit);
                    }

                    execute = (List<UserFeedMaster>) query.getResultList();
                    cursor = JPACursorHelper.getCursor(execute);
                    if (cursor != null)
                        cursorString = cursor.toWebSafeString();

                    // Tight loop for fetching all entities from datastore and
                    // accomodate
                    // for lazy fetch.
                    for (UserFeedMaster obj : execute)
                        ;
                } finally {
                    mgr.close();
                }

                return CollectionResponse.<tableFresopnce> builder().setItems(execute)
                        .setNextPageToken(cursorString).build();
            }

【问题讨论】:

    标签: android google-app-engine jpa google-cloud-datastore google-cloud-endpoints


    【解决方案1】:

    您不能传递“username1,username2”并期待任何结果,除非您有用户名“username1,username2”的人。您必须将 List 传递给 IN 查询,而不是 String。

    我认为这与您在对 blob 键使用 IN 查询时遇到错误的原因相同(您之前的问题)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-05-25
      • 2012-11-03
      • 2011-01-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多