HQL - 两个相同查询之间的差异 [英] HQL - difference between two same queries

查看:134
本文介绍了HQL - 两个相同查询之间的差异的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么这个查询工作正常:

pre $ 查询查询= session.createQuery(来自Table选项卡);

此查询:

  Query query = session 
.createQuery(从Tab选项卡中选择tab.col1,tab.col2,tab.col3);

这就是我对两种查询所做的事情:

  dataList = query.list(); (表项:dataList)

{
System.out.println(item.getCol1();
}
pre>

报告:

  java.lang.ClassCastException:[Ljava .lang.Object;无法转换为table.Table 
at test.TestCriteria.main(TestCriteria.java:35)

您能帮忙吗?

表格通常映射到实体bean中,并且所有列都是正确的。


<我相信 second 查询,结果是一个<$ c
$ b $ pre $对象[]行=(对象[c] ])dataList.get(i);
Object col1Value = row [0];
Object col2Value = row [1];
Object col3Value = row [2];

我有这个猜测在中使用Ljava.lang.Object; 异常跟踪。


Why does this query work normal:

Query query = session.createQuery("from Table tab");

And this query:

Query query = session
  .createQuery("select tab.col1, tab.col2, tab.col3 from Table tab");

And that's what I'm doing with both queries:

dataList = query.list();
for (Table item : dataList)
{
  System.out.println(item.getCol1();
}

reports:

java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to table.Table
at test.TestCriteria.main(TestCriteria.java:35)

Could you help?

Table is normally mapped in entity bean and all the columns are correct.

解决方案

I believe in the second query, the result is a List<Object[]>:

Object[] row = (Object[]) dataList.get(i);
Object col1Value = row[0];
Object col2Value = row[1];
Object col3Value = row[2];

I have this guess observing Ljava.lang.Object; in the exception trace.

这篇关于HQL - 两个相同查询之间的差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆