简体   繁体   English

Java:如何分配或读取从 postgresql 方法返回的 JSON 数据查询到 Z9CE3D1Z48930F196A0764 存储库。 [查询:SELECT row_to_json(…)]

[英]Java: How to assign or read JSON data returned from a postgresql Query into JPA Repository method. [query: SELECT row_to_json(…)]

I have the below code situated in the JpaRepository on a spring boot project, the query returns a JSON structured as GeoJson as below.我在 spring 引导项目的 JpaRepository 中有以下代码,查询返回一个 JSON 结构为 GeoJson,如下所示。

I am getting the Error: Resolved [org.springframework.orm.jpa.JpaSystemException: No Dialect mapping for JDBC type: 1111;我收到错误消息:已解决 [org.springframework.orm.jpa.JpaSystemException: No Dialect mapping for JDBC 类型: nested exception is org.hibernate.MappingException: No Dialect mapping for JDBC type: 1111] *嵌套异常是 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);

In application.properties file i set my Dialect to/as:在 application.properties 文件中,我将方言设置为/为:

spring.jpa.database-platform=org.hibernate.spatial.dialect.postgis.PostgisDialect

The Query returns a GeoJson FeatureCollection Object, and i want to assign or be able to read it into java.查询返回 GeoJson FeatureCollection Object,我想将其分配或能够将其读入 java。

Please bare with me with the way i asked the question, i am new here.请以我提出问题的方式与我裸露,我是新来的。

returned GeoJson would look something like this:返回的 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"}}]}

I don't know what you are trying to achieve here exactly, but guess you need to use String as return type and parse that JSON string in another method.我不知道你究竟想在这里实现什么,但猜想你需要使用String作为返回类型并用另一种方法解析 JSON 字符串。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM