I am using JPA through Java EE and have the following native postgresql query:
@NamedNativeQuery(name = "Player.getStandardDev", query ="SELECT STDDEV(?1) FROM Player WHERE ?2 IS NOT NULL")
(I realise the check for IS NOT NULL is probably not needed, but this is not the source of the problem in this case).
I then have the following code trying to execute the query:
Query query = getEntityManager().createNamedQuery("Player.getStandardDev");
query.setParameter(1, attribute);
query.setParameter(2, attribute);
return (BigDecimal) query.getSingleResult();
When getSingleResult() is called, I receive the following error:
org.postgresql.util.PSQLException: ERROR: function stddev(character varying) does not exist
Hint: No function matches the given name and argument types. You might need to add explicit type casts.
Position: 8
I assume this is because the calls to setParameter are not working correctly and so are not replacing the ?s
Is there any other way to use native queries where you can set parameters.