简体   繁体   English

如何选择条件等于null的位置。

[英]How to select where condition equal null.

SQL statement: SQL语句:

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

HQL statement: HQL声明:

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

I got error. 我出错了。 so how to write HQL to get result same to above sql statement? 那么如何编写HQL以得到与上述sql语句相同的结果?

尝试使用IS EMPTY应该可以。

Are senderId and receiverId foreign keys? 是senderId和ReceiverId外键吗? if yes, then suppose senderId is a column of Sender table and receiverId is a column of Receiver table try this one: 如果是,则假设senderId是Sender表的一列,并且receiveId是Receiver表的一列,请尝试以下操作:

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

OR 要么

Select msg FROM Message msg
WHERE msg.senderId = :senderId and msg.receiverId = :receiverId
 and msg.dateReceived is null

I have solved it by 我已经解决了

HQL Query : FROM Message WHERE senderId = :senderId and receiverId = :receiverId and dateReceived = null HQL查询:在消息来源中senderId =:senderId和receiverId =:receiverId和dateReceived = null

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在@Query 中,我需要查询DB 到select 一行,其中一列是null。 我正在使用 JpaRepository - in @Query , I need to query DB to select a row where a column is null. I am using JpaRepository AndroidAPI.metadata()为空。 如何解决? - AndroidAPI.metadata() Is Null. How to Fix It? 是.equal()方法在JAVA内部检查空条件 - is .equal() method checks null condition internally in JAVA 当参数为 null 时如何从本机查询中排除 where 条件 - How to exclude the where condition from the native query when the parameter is null FindFragmentByTag返回null。 - FindFragmentByTag returns null. Java数组:向数组添加了对象,但为null。 怎么修改? - Java Arrays: Added object to array but is null. How to modify? 如何防止“提供的文档路径不得为 null”。 火库? - How to prevent “Provided document path must not be null.” Firestore? JDBC - 选择列为NULL的位置 - JDBC - select where column is NULL 在Java DB2 JDBC中:如何在WHERE子句中为SELECT语句使用null参数,其中值可以为null或不为null? - In Java DB2 JDBC: How can one use null parameters in a WHERE clause for a SELECT statement where the value can be either null or not null? Android Room Sqlite没有这样的列,而不是在WHERE条件下使用等号(=) - Android Room Sqlite no such column than using equal sign (=) in WHERE condition
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM