简体   繁体   中英

JPA modify my native query using postgis <#> operator

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM