Object[]
如果我选择特定列,为什么我必须使用打印列表:
Session session = DaoSF.getSessionFactory().openSession();
List<Object[]> list = new ArrayList<Object[]>(); /* Object[] */
Query criteria = session.createQuery(
"select test.col1, test.col2, test.col3
"from Test test " +
"group by test.col1, test.col2, test.col3");
list = criteria.list();
for (Object[] item : list)
{
System.out.println(item[1] + ", " + item[2] + ", " + item[3]);
}
为什么可以使用原始 Test 对象迭代相同的选择(选择 * - 而不是特定的列)?
List<Test> list = new ArrayList<Test>(); /* Test */
Query criteria = session.createQuery(
"from Test test " +
"group by test.col1, test.col2, test.col3");
list = criteria.list();
for (Test item : list)
{
System.out.println(item.getCol1 + ", " + item.getCol2 + ", " + item.getCol3);
}
是否可以“转换”Object[]
为Test
对象?