views:

11

answers:

0

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..
}

}