我有一个PostgreSQL表,其中包含许多其他列的空间列point
。此空间列应以geoJson-Format为其内容提供。
普通的SQL应如下所示:
select column1, column2, column3, ST_AsGeoJSON(point) from table;
回写:
update table set column1 = 'abc', column2 = 'def', column3 = 'ghi',
point = ST_GeomFromGeoJSON('{ ... geojson ... }')
where id = ??;
我知道hibernate有一个名为hibernate-spatial的扩展。但是这个扩展名是postgis 1.5,它可以读取geoJson,但不解析并将geoJson写回PostgreSQL。另一个缺点:空间操作(如转换)是在服务器端完成的,而不是在数据库端完成的。
是否有可能将sql-function注入这样的查询:
EntityManager em = emFactory.createEntityManager();
myModel selected = em.find(myModel.class, 1);
在myModel中,几何体的已用列应为String
或表示geoJson的继承类型的String。
我找到了Hibernate Dialects,但似乎它们只适用于HQL(或JPL)。我想透明地使用这个geojson - 而不是与HQL结合使用(我强迫在代码中编写SQL,我不想要)。
也可以使用setCustomWrite
和setCustomRead,但我没有找到任何使用它们的示例。
为了防止回答我为什么要在postgis-geometry中保留类型 - 由于db-side上的其他空间相关操作,它应该保留在这种类型中。
答案 0 :(得分:0)
Dialect is for hibernate你只需要使用postgres驱动程序......