IN条件仅适用于单值数据存储查询 - Google应用引擎

时间:2022-09-11 13:36:56

I want to execute IN query on my app engine datastore app engine. Here i am facing weird problem.The problem is that when i pass single value to IN criteria then it returns proper records but when i pass multiple values to IN criteria then it returns null response. If i execute same query on server then it returns proper output.I don't know what is the problem with my code. I am using endpoint classes in my android client and i am passing values from android client to app engine backend. Please help me to solve this problem. Thank you.

我想在我的app引擎数据存储区应用引擎上执行IN查询。在这里,我面临着奇怪的问题。问题是,当我将单个值传递给IN条件时,它会返回正确的记录,但是当我将多个值传递给IN条件时,它会返回null响应。如果我在服务器上执行相同的查询然后它返回正确的输出。我不知道我的代码有什么问题。我在我的Android客户端使用端点类,我将值从android客户端传递到app引擎后端。请帮我解决这个问题。谢谢。

UPDATE :

更新:

I changed my code as shown below and now i am passing ArrayList as a parameter and its working.

我改变了我的代码,如下所示,现在我传递ArrayList作为参数和它的工作。

Code:

码:

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

1 个解决方案

#1


2  

You cannot pass "username1,username2" and expect any results, unless you have someone with a username "username1,username2". You have to pass a List to the IN query, not a String.

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

I assume this is the same reason why you were getting an error when using an IN query for blob keys (your previous question).

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

#1


2  

You cannot pass "username1,username2" and expect any results, unless you have someone with a username "username1,username2". You have to pass a List to the IN query, not a String.

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

I assume this is the same reason why you were getting an error when using an IN query for blob keys (your previous question).

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