问题
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.
回答1:
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 "
来源:https://stackoverflow.com/questions/58958908/ordinal-parameter-not-bound-2-in-query-annotation