【发布时间】:2015-07-19 02:19:13
【问题描述】:
我有以下 HQL:
select r from Route r where r.startingStop.description = 'Railway Station'
现在,我已将 HQL 修改为:
select r from Route r where r.startingStop.description = 'Railway Station' or r.destinationStop.description = 'Railway Station'
我得到以下异常:
org.hibernate.exception.DataException: Subquery returns more than 1 row
我已经在 Stackoverflow 上研究过这个异常,但我仍然无法解决我的问题。提前致谢。
我的字段(单向映射):
@ManyToOne(fetch=FetchType.EAGER)
@JoinColumn(name = "starting_stop")
private BusStop startingStop;
@ManyToOne(fetch=FetchType.EAGER)
@JoinColumn(name = "destination_stop")
private BusStop destinationStop;
【问题讨论】:
-
您将其用作子查询还是整个查询?
-
我怀疑这个查询是否是引发该异常的查询。发布完整的堆栈跟踪和相关代码(即引发此异常的代码)。
-
这是完整的查询
-
如果您只想从数据库返回单个结果,请使用
LIMIT 1就像select r from Route r where r.startingStop.description = 'Railway Station' or r.destinationStop.description = 'Railway Station' LIMIT 1一样 -
首先,不,我不想要一个结果。其次,LIMIT 从未被 HQL 支持