当没有与之比较的值时,如何在HQL中执行OR,因为它给出了java.lang.NullPointerException错误?
这是一句HQL当没有与之比较的值时,如何在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查询中的或有问题,除了优先顺序在或和之间可能存在的逻辑问题
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?斯威埃特