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, 2开发者_Python百科1]
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..
}
}
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());
}
精彩评论