【发布时间】:2016-12-03 01:39:58
【问题描述】:
刚开始使用 postgis 和 hibernate statial,但在查询时遇到了一些问题。
目标:从(其)几何类型对象中获得博物馆
在我的数据库中,我得到了这个专栏:
name: geom
type: geometry(Point,4326))
that contains something like: 0101000020E6100000004C8E1516D(...)
for each museum
然后,我有一个博物馆课:
@Column(name = "geom", columnDefinition = "geometry(Point,4326)")
private Geometry geometry;
这是我的查询:
WKTReader fromText = new WKTReader();
try {
//LON and LAT are the museum's coordinates
Geometry geom = fromText.read("POINT("+lon+" "+lat+")");
Session hibernateSession = getCurrentSession();
Museum result = hibernateSession
.createQuery("from Museum where geometry = :geometry")
.setParameter("geometry", geom).uniqueResult();
return result;
} catch (ParseException e) {
(...)
}
但是当我尝试执行它时,我得到了这个错误:
ERROR: operator is not unique: geometry = bytea
Indice : Could not choose a best candidate operator. You might need to add explicit type casts.
所以我在想,也许 Hibernate 中的 Geometry 和 Postgis 中的 Geometry 不一样? 关于如何让它发挥作用的任何想法?
谢谢!
【问题讨论】:
标签: hibernate geometry hql postgis spatial