2

SQL 语句:

select * FROM Message
 WHERE senderId = 126 and receiverId = 125
   and dateReceived is null

HQL 语句:

 FROM Message
WHERE senderId = :senderId and receiverId = :receiverId
 and dateReceived is null

我有错误。那么如何编写 HQL 以获得与上述 sql 语句相同的结果呢?

4

3 回答 3

3

尝试使用 IS EMPTY 应该可以。

于 2012-04-24T08:09:32.720 回答
2

senderId 和receiverId 是外键吗?如果是,那么假设 senderId 是 Sender 表的一列,receiverId 是 Receiver 表的一列,试试这个:

select msg FROM Message msg
 WHERE msg.Sender.senderId = 126 and msg.Receiver.receiverId = 125
   and msg.dateReceived is null

或者

Select msg FROM Message msg
WHERE msg.senderId = :senderId and msg.receiverId = :receiverId
 and msg.dateReceived is null
于 2012-04-24T08:18:32.483 回答
0

我已经解决了

HQL 查询:FROM Message WHERE senderId = :senderId 和 receiverId = :receiverId 和 dateReceived = null

于 2012-04-25T10:10:51.927 回答