Question

Why JPA modifies my native query?

For example:

Query q = entityManager.createNativeQuery("select id from edges order by st_geomfromtext(?,4326) <#> geom_way limit 1");
q.setParameter(1, "POINT( " + longitude + " " + latitude + ")");
q.getSingleResult();

Pay attention in <#> operator, used in postgis.

This code result in an error:

javax.persistence.PersistenceException: Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.5.1.v20130918-f2b9fc5): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: org.postgresql.util.PSQLException: No se ha especificado un valor para el parámetro 2.
Error Code: 0
Call: select id from edges order by st_geomfromtext(?,4326) <? geom_way limit 1
    bind => [null]
Query: DataReadQuery(sql="select id from edges order by st_geomfromtext(?,4326) <? geom_way limit 1")

Why does EclipseLink 2.5.1 replaced "<#>" with "<?" ?

Thanks

Was it helpful?

Solution

EclipseLink uses the # as a parameter delimiter in native SQL queries, and left this processing in for JPA support. You can change the default character used by specifying a property described here http://www.eclipse.org/eclipselink/api/2.3/org/eclipse/persistence/config/QueryHints.html#PARAMETER_DELIMITER to some character that won't be used so it doesn't interfere with your query.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top