Spring 3.1.0、Hibernate 4、JDK 7 を Tomcat 7 に使用して、itr.next() メソッドで ClassCastException を取得しています。aaData オブジェクトにはデータが含まれています。
List<CustomerList> aaData = customerlistDaoimpl.getCustomerList();
/*
* putting data in a JSON form that DataTables recognizes
*/
String data = "{\"sEcho\": 3, \"iTotalRecords\": " + count + ",\"iTotalDisplayRecords\": " + count + ",\"aaData\": [ ";
Iterator<CustomerList> itr = aaData.iterator();
while(itr.hasNext()){
CustomerList cl = (CustomerList) itr.next();
data += "[\"" + cl.getName() + "\",\"" + cl.getAddress() + "\",\"" + cl.getZipcode() + "\",\"" +
cl.getPhone() + "\",\"" + cl.getCity() + "\",\"" + cl.getCountry() + "\",\"" + cl.getNote() + "\" ] ";
count++;
}
data += "]}";
マイダオ
@SuppressWarnings("unchecked")
@Override
public List<CustomerList> getCustomerList() {
List<CustomerList> cuList = null;
Session session = null;
try{
session = sessionfactory.openSession();
session.beginTransaction();
cuList = session.createSQLQuery("select * from customer_list").list();
session.getTransaction().commit();
}catch (RuntimeException e){
System.out.println(e.getMessage());
}
finally
{
if(session != null){
session.close();
}
}
return cuList;
}
そしてトレースバック
SEVERE: パス [/SPTestJs] のコンテキストでサーブレット [sptestjs] の Servlet.service() が例外をスローしました [要求処理に失敗しました。ネストされた例外は java.lang.ClassCastException: [Ljava.lang.Object; 根本原因 java.lang.ClassCastException: [Ljava.lang.Object; com.sptestjs.implementation.CustomerList] にキャストできません。com.sptestjs.implementation.controller.HomeController.getCustomerList(HomeController.java:85) で com.sptestjs.implementation.CustomerList にキャストできません。 (不明なソース) で sun.reflect.DelegatingMethodAccessorImpl.invoke(不明なソース)
私は電話を見つけました
SQLQuery cuSQLQuery = session.createSQLQuery("select * from customer_list");
SQLQuery インスタンスを返し、そのリストは Object 要素の ArrayList 型です。
Query cuQuery = session.createQuery("from customer_list");
戻りますnull
。