when i iterate by using the foreach loop, i get ClassCast Exception. i dont know why ?
public List<MailData> getAllMailData() {
String strqry="select c.created_time as created_time, c.hangup_time as hangup_time, c.direction as direction ,
c.sip_endpoint_disposition as sip_endpoint_disposition, v.cid_number as cid_number, v.in_folder as in_folder,
v.message_len as message_len,v.read_flags as read_flags, v.username as username from onyxcxm_db.cdr c
inner join onyxcxm_db.mail_msgs v on c.orig_id=v.uuid";
List<MailData> listMailData = (List<MailData>)getSession().createNativeQuery(strqry).list();
for(MailData md:listMailData){
System.out.println(md.getcreated_time); //line 44
}
getSession().flush();
return listvoiceMailData;
}
and Error like,
SEVERE: Servlet.service() for servlet [dispatcher] in context with path [/hello] threw exception [Request processing failed; nested exception is java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to com.my.models.MailData] with root cause java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to com.my.models.MailData at com.neron.daoImpl.MailDataDaoImpl.getAllMailData(MailDataDaoImpl.java:44) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) Can any one solve it ? Thanks..