Question

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.

UPDATE :

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

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();
            }
Was it helpful?

Solution

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.

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top