GAE: Comparing String value returning false results when executing JDO query

丶灬走出姿态 提交于 2019-12-12 03:16:46

问题


For an iOS project I'm using GAE (Java stack) to store the user's device token and use it to send Push notifications.

I have a Device entity which contains several fields, including "appVersion" field of type String. The database contains some Devices with version 1 and some with version 2.

When I run a JDO query to find all devices with "appVersion" equals to 2 it returns the expected result, but when I do the same with version 1 the query return no result, although there are Entities which match this condition.

This is the code:

javax.jdo.Query query = _pm.newQuery(Device.class, "appVersion == appVersionParams");

query.declareParameters(String.class.getName()+" appVersionParams");

List<Device> results = (List<Device>) query.execute(message.getAppVersion());

I verified several times that the Device Entities with version 1 are stored correctly (the type is String and contains the right, trimmed value which indeed match exactly to the parameter I'm passing).

I first encountered this issue on the Dev environment, so I deleted the local DB and created test entities and run the Query again - this time it returned the expected results for version 1 and 2. But after I restarted the server it again returned false results for version 1 (while doing good with version 2). Hoping it was just a bug on the local dev env. I deployed it to the production environment and it returned only 4 entities (there are few thousands match this condition) - all entities were stored in the same way/API.

I also tried to switch from JDO to the low level APIs to fetch the Entities but i got the same weird behavior. This is the code for it:

Query q = new Query("Device");
q.addFilter("appVersion", FilterOperator.EQUAL, message.getAppVersion());

I'm going nuts here.. what's going on ??


回答1:


The problem was related to a modification I made to the persistent Entity structure/schema without proper use of serialVersionUID. See the question's comments for more details, specifically Viruzzo's one.



来源:https://stackoverflow.com/questions/9228941/gae-comparing-string-value-returning-false-results-when-executing-jdo-query

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!