【问题标题】:JPA modify my native query using postgis <#> operatorJPA 使用 postgis <#> 运算符修改我的本机查询
【发布时间】:2013-12-04 17:12:45
【问题描述】:

为什么 JPA 会修改我的原生查询?

例如:

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();

注意操作符,postgis中使用。

此代码导致错误:

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")

为什么 EclipseLink 2.5.1 将“&lt;#&gt;”替换为“&lt;?”?

谢谢

【问题讨论】:

    标签: java jpa eclipselink jpa-2.0 java-ee-6


    【解决方案1】:

    EclipseLink 在本机 SQL 查询中使用 # 作为参数分隔符,并将此处理留给 JPA 支持。您可以通过将此处描述的属性http://www.eclipse.org/eclipselink/api/2.3/org/eclipse/persistence/config/QueryHints.html#PARAMETER_DELIMITER 更改为某些不会使用的字符来更改使用的默认字符,这样它就不会干扰您的查询。

    【讨论】:

      猜你喜欢
      • 2017-08-11
      • 2019-09-19
      • 2018-05-29
      • 1970-01-01
      • 2020-09-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多