[英]How to execute a postgresql json function query in jpa nativequery?
[英]Java: How to assign or read JSON data returned from a postgresql Query into JPA Repository method. [query: SELECT row_to_json(…)]
我在 spring 引导项目的 JpaRepository 中有以下代码,查询返回一个 JSON 结构为 GeoJson,如下所示。
我收到错误消息:已解决 [org.springframework.orm.jpa.JpaSystemException: No Dialect mapping for JDBC 类型: 嵌套异常是 org.hibernate.MappingException: No Dialect mapping for JDBC type: 1111] *
String queryString = "SELECT row_to_json(fc)\n" +
" FROM ( SELECT 'FeatureCollection' As type, array_to_json(array_agg(f)) As features\n" +
" FROM (SELECT 'Feature' As type\n" +
" , ST_AsGeoJSON(lg.column1) As geometry\n" +
" , row_to_json((column2, column3)) As properties\n" +
" FROM public.table As lg ) As f ) As fc;";
@Query(value=queryString, nativeQuery=true)
Json getData(@Param("id") Long id);
在 application.properties 文件中,我将方言设置为/为:
spring.jpa.database-platform=org.hibernate.spatial.dialect.postgis.PostgisDialect
查询返回 GeoJson FeatureCollection Object,我想将其分配或能够将其读入 java。
请以我提出问题的方式与我裸露,我是新来的。
返回的 GeoJson 看起来像这样:
{"type" : "FeatureCollection", "features" : [{"type": "Feature", "geometry": {"type":"Point","coordinates":[1,1]}, "properties": {"id": 1, "name": "one"}}, {"type": "Feature", "geometry": {"type":"Point","coordinates":[2,2]}, "properties": {"id": 2, "name": "two"}}, {"type": "Feature", "geometry": {"type":"Point","coordinates":[3,3]}, "properties": {"id": 3, "name": "three"}}]}
我不知道你究竟想在这里实现什么,但猜想你需要使用String
作为返回类型并用另一种方法解析 JSON 字符串。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.