HQL exception when adding OR operator
I have the following HQL:
select r from Route r where r.startingStop.description = 'Railway Station'
Now I changed my HQL to:
select r from Route r where r.startingStop.description = 'Railway Station' or r.destinationStop.description = 'Railway Station'
And I am getting the following exception:
org.hibernate.exception.DataException: Subquery returns more than 1 row
I researched Stackoverflow about this exception, but I still couldn't solve my problem. Thanks in advance.
My fields (unidirectional mapping):
@ManyToOne(fetch=FetchType.EAGER)
@JoinColumn(name = "starting_stop")
private BusStop startingStop;
@ManyToOne(fetch=FetchType.EAGER)
@JoinColumn(name = "destination_stop")
private BusStop destinationStop;
source to share
While we may not know your desired choice or conclusion, here are some tips to help you solve the problem.
Reason . External demand should use one of the keywords ANY
, ALL
, IN
or NOT IN
to specify values for comparison, because the subquery returns more than one row .
Action . Use ANY
, ALL
, IN
or NOT IN
to specify which values are compared or rewrite the query to retrieve only one row.
Offer . Try to add a rownum=1
subquery to your conditions as well if you DO NOT care about the value from the list or are NOT sure they are the same.
source to share
The query works fine, but the problem is that it returns more than 1 row. You are trying to use the result as 1 object, but with a clause, or it returns more than one and throws an exception. If you use it as a subquery, for example, and you say:
Something = (your query), it won't work because your query is returning 2 results.
If you try to map it to a single object it will also be a problem because you will get more than 1 result.
source to share