How to select from HQL

hibernate, hql, java, select

Solution

You can select fields/columns using HQL. Looks like the following:

select
    SenseDate,
    SenseValue
from
    UserData
where
    NetworkID = '23'
and
    IODeviceID = '129'
and
    SenseDate >= DateAdd(d, -1, GETDATE())
and
    SenseDate <= GETDATE()

When you execute this you will receive a list of arrays of objects:

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

Each element in the list represents a found row. The array itself contains the two selected fields in the same order you declared them in the statement.

Problem

I'm new to HQL and have a SQL expression I need converted but am unable to select the SQL statement is: ``` select SenseDate as Time,SenseValue as Value from UserData where NetworkID = '23' and IODeviceID = '129' and SenseDate >= DateAdd("d",-1, GETDATE()) and SenseDate<=GETDATE() ``` I can run this part in HQL without problems: ``` from UserData where NetworkID = '23' and IODeviceID = '129' and SenseDate >= DateAdd(d,-1, GETDATE()) and SenseDate<=GETDATE() ``` However I only want the `SenseDate` and `SenseValue` values returned, could someone show me how to select as when I try to add `select SenseDate, SenseValue` etc. I keep getting errors in Netbeans

Original source