Java – how to select from HQL

I am a novice to HQL and have an SQL expression that I need to convert, but I cannot select an SQL statement:

select SenseDate as Time,SenseValue as Value
from UserData
where NetworkID = '23'
and IOdeviceid = '129'
and SenseDate >=  DateAdd("d",-1,GETDATE())
and SenseDate<=GETDATE()@H_502_3@ 
 

我可以在HQL中运行这部分而不会出现问题:

from UserData 
where NetworkID = '23'
and IOdeviceid = '129'
and SenseDate >=  DateAdd(d,GETDATE())
and SenseDate<=GETDATE()@H_502_3@ 
 

但是我只想要返回SenseDate和SenseValue值,有人可以告诉我如何选择当我尝试添加select SenseDate,SenseValue等时我会在Netbeans中遇到错误

Solution

You can use HQL to select fields / columns It looks like this:

select
    SenseDate,SenseValue
from
    UserData
where
    NetworkID = '23'
and
    IOdeviceid = '129'
and
    SenseDate >= DateAdd(d,GETDATE())
and
    SenseDate <= GETDATE()@H_502_3@ 
 

执行此操作时,您将收到一个对象数组列表:

final List<Object[]> values = query.list();@H_502_3@ 
 

列表中的每个元素代表一个找到的行.数组本身包含两个选定的字段,其顺序与您在语句中声明的顺序相同.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>