0

我的表描述是

desc sensor_log_history;
+-------------+-----------------+------+-----+-------------------+-----------------------------+
| Field       | Type            | Null | Key | Default           | Extra                       |
+-------------+-----------------+------+-----+-------------------+-----------------------------+
| AutoPk      | int(4) unsigned | NO   | MUL | NULL              |                             |
| sensorName  | varchar(20)     | NO   |     | NULL              |                             |
| SensorValue | double(65,2)    | NO   |     | 0.00              |                             |
| timest      | timestamp       | NO   |     | CURRENT_TIMESTAMP | on update CURRENT_TIMESTAMP |
+-------------+-----------------+------+-----+-------------------+-----------------------------+
4 rows in set (0.00 sec)

我的查询是

SELECT AutoPk,Result1.sensorName, SensorValue,Result1.timest FROM (SELECT MAX(timest) AS timest, sensorName FROM sensor_log_history GROUP BY sensorName) AS Result1 INNER JOIN sensor_log_history ON Result1.timest = sensor_log_history.timest WHERE Result1.sensorName = sensor_log_history.sensorName ;

如何使用休眠执行此查询。Hibernate 应该返回一个类型为sensor_log_history.? 的对象列表。

4

1 回答 1

0

只需在您的 JAVA 应用程序中创建一个 POJO,然后使用 hibernate 将此表映射到该 POJO。然后触发 HQL 查询:“FROM”。

于 2013-09-20T09:31:53.673 回答