我正在尝试使用 hibernate 获取表中的最后数据,如以下代码片段所示
query.setMaxResults(1);
List<Long[]> rows = query.list();
System.out.println("current row>>>>>> " +rows.toString());
for (Long[] row: rows) {
System.out.println(" ------------------- ");
long val = (Long) row[6];
System.out.println("current file: " + val);
}
}catch(Exception ex){
ex.printStackTrace();
}
这是我的查询
Query query = session.createQuery("select f.currentfile.id from File f order by f.id DESC");
我在这行代码中遇到错误
java.lang.ClassCastException: java.lang.Long cannot be cast to [Ljava.lang.Long;
for (Long[] row: rows) {
请问哪里出了问题?
最佳答案
您的查询返回List<Long>
并且您正在分配 List<Long[]>
Long is java.lang.Long
Long[] is [Ljava.lang.Long
关于java.lang.ClassCastException : java. lang.Long 无法转换为 [Ljava.lang.Long;迭代数据库中的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39469321/