使用“INTO” JDOQL 中的关键字与 GAE

发布于 2024-09-27 13:11:41 字数 1127 浏览 1 评论 0原文

我有一个持久的类“会议”,其中有“分钟”和“小时”字段。我只需要这两个字段来填充用户界面中的下拉列表。 我找到的示例 告诉我,我可以创建一个简单的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

谜兔 2024-10-04 13:11:41

GAE 数据存储不支持 INTO。我认为您找到的示例是针对 RDBMS 进行查询的。

在 GAE/DS 中,您可以只获取密钥或整个对象;你需要获取整个对象。

List<Meeting> meetingTimes = (List<Meeting>) pm.newQuery(Meeting.class)
    .execute();

for (Meeting meeting : meetingTimes) {
    MyTime myTime = new MyTime(meeting.hour, meeting.hour);
    System.out.println(myTime.getMyHour());
    System.out.println(myTime.getMyMinute());
}

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.

List<Meeting> meetingTimes = (List<Meeting>) pm.newQuery(Meeting.class)
    .execute();

for (Meeting meeting : meetingTimes) {
    MyTime myTime = new MyTime(meeting.hour, meeting.hour);
    System.out.println(myTime.getMyHour());
    System.out.println(myTime.getMyMinute());
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文