0
有了這個代碼項目:水溼檢索DB HQL
Session session = HibernateUtil.getSessionFactory().getCurrentSession();
session.beginTransaction();
Query query = session.createQuery("from DBUser where id=1");
for(Iterator it=query.iterate();it.hasNext();){
Object[] row = (Object[]) it.next();
System.out.println("ID: " + row[0]);
System.out.println("Name: " + row[1]);
System.out.println("Amount: " + row[2]);
}
發生一個錯誤:java.lang.ClassCastException: com.mycompany.app.DBUser cannot be cast to [Ljava.lang.Object;
有可能是更簡單的方法來檢索表中的單個元素?