I want to perform a native/raw mysql query using hibernate, I have this:
sessionFactory.getCurrentSession().createSQLQuery(
"update table1 set someCounter = someCounter + 1 where id = ?")
.setParameter(1, someId)
.executeUpdate();
I’m getting the error:
threw exception [Request processing failed; nested exception is
org.hibernate.QueryParameterException: Position beyond number of declared ordinal
parameters. Remember that ordinal parameters are 1-based! Position: 2]
with root cause
org.hibernate.QueryParameterException: Position beyond number of declared ordinal
parameters. Remember that ordinal parameters are 1-based! Position: 2
What’s wrong here?
Use index as
0since the parameter index start from0.Since you are using Hibernate, you can use the named parameter as well i.e.