使用“INTO” JDOQL 中的关键字与 GAE
我有一个持久的类“会议”,其中有“分钟”和“小时”字段。我只需要这两个字段来填充用户界面中的下拉列表。 我找到的示例 告诉我,我可以创建一个简单的 bean,只容纳这两个字段,但我收到一条错误,指出它无法将 Integer 转换为 MyTime 对象。显然,它没有将数据映射到 bean,不幸的是,这是我能找到的唯一示例。
String query = "select hour as myHour, minute as myMinute into " + MyTime.class.getName() + " from " + Meeting.class.getName(); //+
List<MyTime> times = (List<MyTime>)pm.newQuery(query).execute();
for(int i=0; i<times.size(); i++) {
MyTime myTime = (MyTime)times.get(i);
System.out.println(myTime.getMyHour());
System.out.println(myTime.getMyMinute());
}
以下是运行执行后在调试模式下的“times”的样子: [0, 0, 0, 0, 0, 0, 8, 10, 21]
然后,当我尝试将时间索引转换为 MyTime 对象时,我在 for 循环中收到错误。 java.lang.ClassCastException:java.lang.Integer 无法转换为 com.emooney.meeting.beans.MyTime
有什么想法可以获取此数据,而不必为每次会议带回整个“会议”对象吗?
这是 MyTime bean:
public class MyTime {
public int myHour;
public int myMinute;
.. getters and setters..
}
}
I have a persistent class, 'Meeting' that has a 'minute' and 'hour' field among others. I only need these two fields to populate a dropdown in my ui. The example I found tells me that I can create a simple bean that would house just these two fields but I'm getting an error saying that it can't convert an Integer to a MyTime object. It's obviously not mapping the data to the bean and unfortunately, this is the only example I can find.
String query = "select hour as myHour, minute as myMinute into " + MyTime.class.getName() + " from " + Meeting.class.getName(); //+
List<MyTime> times = (List<MyTime>)pm.newQuery(query).execute();
for(int i=0; i<times.size(); i++) {
MyTime myTime = (MyTime)times.get(i);
System.out.println(myTime.getMyHour());
System.out.println(myTime.getMyMinute());
}
Here's what 'times' looks like in debug mode after execute is run:
[0, 0, 0, 0, 0, 0, 8, 10, 21]
And then I get my error in the for loop when I attempt to cast and index of times to a MyTime object.
java.lang.ClassCastException: java.lang.Integer cannot be cast to com.emooney.meeting.beans.MyTime
Any ideas how I can get this data without having to bring the entire 'Meeting' object back for each meeting?
Here's the MyTime bean:
public class MyTime {
public int myHour;
public int myMinute;
.. getters and setters..
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
GAE 数据存储不支持 INTO。我认为您找到的示例是针对 RDBMS 进行查询的。
在 GAE/DS 中,您可以只获取密钥或整个对象;你需要获取整个对象。
INTO isn't supported on GAE Datastore. I think the example you found is for querying against an rdbms.
In GAE/DS you can either fetch either just the key or the whole object; you need to fetch the whole object.