I am getting following error when I try to run this query.
org.hibernate.QueryException: Ordinal parameter not bound : 2",
@Query(value = "SELECT amu " +
"FROM Upgrade amu " +
"INNER JOIN FETCH amu.visibility v " +
" WHERE v IN ?2 " +
"AND amu.id= '?1' "
)
Optional<Upgrade> myFindMethod(final String uid, final String cid);
If I change " WHERE v IN ?2 "
with " WHERE v IN ?2 OR v IN ?1 "
, then it works. I have no idea why it does not work. Any idea?
Note: Visibility is type of Set<String>
in the Upgrade class.
To add to Jens' answer: be aware of the spaces!
For example, this will throw the error:
"WHERE v IN ?2" +
"AND amu.id= ?1 "
And this will work fine:
"WHERE v IN ?2 " +
"AND amu.id= ?1 "
It's a minute difference that's easy to overlook.
The problem is that you have only one bind parameter declared in the query but have actually two parameters in the method.
This is because in "AND amu.id= '?1' "
what looks like a bind parameter is actually a string literal due to the enclosing quotes.
If you want that to be handled as a bind parameter remove the quotes: "AND amu.id= ?1 "
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With