【发布时间】:2015-07-27 09:18:29
【问题描述】:
我有一个表格站点存储了我的站点信息以及纬度和经度。
ozssc=> \d site;
......
site_latitude | double precision |
site_longitude | double precision |
......
我添加到我的 PostgreSQL 服务器 9.4.3
CREATE EXTENSION cube;
CREATE EXTENSION earthdistance;
所有函数都添加到我的数据库中,我将函数所有者更改为我的登录用户。
当我尝试 PSQL 到我的服务器并执行时:
ozssc=> select * from site s where earth_box('-28.175613','153.52578399999993',100000) @> ll_to_earth(s.site_latitude,s.site_longitude);
ERROR: function earth_box(unknown, unknown, integer) does not exist
LINE 1: select * from site s where earth_box('-28.175613','153.52578...
^
HINT: No function matches the given name and argument types. You might need to add explicit type casts.
当我尝试将 earth_box 函数放入 JPA 中的命名查询中时:
@NamedQuery(name = "SiteEntity.findByEarthDistance", query = "SELECT s FROM SiteEntity s WHERE earth_box((ll_to_earth( :positionLatitude, :positionLongitude), :range) @> ll_to_earth(s.siteLatitude,s.siteLongitude))"),
我的intelliJ抱怨没有功能匹配??
当我尝试将我的 JAVAEE 应用程序部署到我的 webLogic 12c 时,我发现错误如下:
Message icon - Error An error occurred during activation of changes, please see the log for details.
Message icon - Error Exception [EclipseLink-0] (Eclipse Persistence Services - 2.5.2.v20140319-9ad6abd): org.eclipse.persistence.exceptions.JPQLException Exception Description: Syntax error parsing [SELECT s FROM SiteEntity s WHERE earth_box((ll_to_earth( :positionLatitude, :positionLongitude), :range) > ll_to_earth(s.siteLatitude,s.siteLongitude))]. [33, 151] The expression is not a valid conditional expression.
Message icon - Error Substituted for missing class Exception [EclipseLink-0] (Eclipse Persistence Services - 2.5.2.v20140319-9ad6abd) - org.eclipse.persistence.exceptions.JPQLException Exception Description: Syntax error parsing [SELECT s FROM SiteEntity s WHERE earth_box((ll_to_earth( :positionLatitude, :positionLongitude), :range) > ll_to_earth(s.siteLatitude,s.siteLongitude))]. [33, 151] The expression is not a valid conditional expression.
我现在迷失了方向,谁能帮帮我!!
再次编辑
我发现 PostgreSQL 9.4 的 earth_box 函数一定有一些 bug,它不能总是得到正确的结果集,我必须将其更改为 earth_distance 函数并使用多选投影才能使其正常工作,较新的 namedQuery 为:
@NamedQuery(name = "SiteEntity.findBySiteLNR", query = "SELECT s, FUNC('earth_distance', FUNC('ll_to_earth',:positionLatitude, :positionLongitude), FUNC('ll_to_earth',s.siteLatitude,s.siteLongitude)) AS dfcl " +
"FROM SiteEntity s WHERE dfcl < :range ORDER BY dfcl"),
我没有使用休眠,而是使用 EclipseLink 和 JPA 2.1,EJB 容器是 Weblogic 12C,EJB 规范 3.1。
【问题讨论】:
标签: java postgresql function jpa named-query