GAE:比较执行JDO查询时返回错误结果的字符串值 [英] GAE: Comparing String value returning false results when executing JDO query

查看:128
本文介绍了GAE:比较执行JDO查询时返回错误结果的字符串值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于iOS项目,我使用GAE(Java堆栈)来存储用户的设备令牌并使用它发送推送通知。



我有一个Device实体其中包含几个字段,包括String类型的appVersion字段。数据库包含一些版本为1的设备,一些版本为2。



当我运行一个JDO查询来查找所有具有appVersion的设备等于2时,结果,但是当我对版本1执行相同的操作时,查询不返回任何结果,尽管实体符合此条件。



这是代码:

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

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

列表<设备> results =(List< Device>)query.execute(message.getAppVersion());

我多次验证版本1的设备实体存储正确(类型是String并包含正确的修剪值确实与我传递的参数完全匹配)。

我首先在开发环境中遇到过这个问题,所以我删除了本地数据库并且创建测试实体并再次运行查询 - 这次它返回了版本1和2的预期结果。但是,在我重新启动服务器之后,它又返回了版本1的错误结果(虽然版本2有效)。希望这只是本地开发环境中的一个bug。我将它部署到生产环境,它只返回4个实体(有几千个匹配这个条件) - 所有实体都以相同的方式/ API存储。



I也尝试从JDO切换到低级API来获取实体,但我得到了相同的奇怪行为。这是它的代码:

 查询q =新的查询(设备); 
q.addFilter(appVersion,FilterOperator.EQUAL,message.getAppVersion());

我会在这里疯狂。发生了什么事?

解决方案

这个问题与我对持久化实体结构/模式所做的修改没有正确使用 serialVersionUID 。查看问题的更多细节的评论,特别是Viruzzo的。

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 ??

解决方案

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.

这篇关于GAE:比较执行JDO查询时返回错误结果的字符串值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆