Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/401.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
当没有与之比较的值时,如何在HQL中执行OR,因为它给出了java.lang.NullPointerException错误?_Java_Mysql_Hql - Fatal编程技术网

当没有与之比较的值时,如何在HQL中执行OR,因为它给出了java.lang.NullPointerException错误?

当没有与之比较的值时,如何在HQL中执行OR,因为它给出了java.lang.NullPointerException错误?,java,mysql,hql,Java,Mysql,Hql,这是一句HQL select r.response as response from Responsemix as r right join r.idOptQuestion as opt where opt.idQuestion=5 and opt.content='Other' or opt.content='Others' order by r.response asc 我不认为这个Hibernate查询中的或有问题,除了优先顺序在或和之间可能存在的逻辑问题

这是一句HQL

    select r.response as response from  Responsemix as r right join r.idOptQuestion
    as opt  where opt.idQuestion=5 and opt.content='Other' or opt.content='Others' 
    order by r.response asc

我不认为这个Hibernate查询中的
有问题,除了优先顺序在或和之间可能存在的逻辑问题

根据您的查询文本,我们推断您可能想要的是:

... where opt.idQuestion=5 and ( opt.content='Other' or opt.content='Others' )
我相信Hibernate也会允许您这样写:

... where opt.idQuestion=5 and opt.content in ('Other','Others')

您的意思是,如果从查询文本中删除以下部分:
“或opt.content='Others'
,则查询可以工作。但是当您将其添加回查询时,Hibernate抛出了一个java.lang.NullPointerException?斯威埃特