提问人:Simonas Petkevičius 提问时间:11/18/2023 最后编辑:Simonas Petkevičius 更新时间:11/18/2023 访问量:15
使用 PostGIS 的本机查询引发 HttpMessageNotWritableException
Native Query with PostGIS Throws HttpMessageNotWritableException
问:
我的Spring Data JPA存储库中有两个查询,一个是用JPQL编写的,另一个是用本机SQL编写的。JPQL 查询可以完美运行,而本机查询会抛出 HttpMessageNotWritableException。这两个查询在所选字段和条件方面几乎相同。
以下是查询:
本机查询:
@Query(value = "SELECT " +
"o.geometry\\:\\:geometry as geometry, " +
"o.center\\:\\:geometry as center, " +
"FROM overlay as o " +
"JOIN company_layer as cl on cl.id = o.layer_id " +
"WHERE o.ts_overlaytext @@ to_tsquery(:searchString) AND o.disabled = false",
nativeQuery = true)
List<MyProjection> findWithNativeQuery(@Param("searchString") String searchString);
JPQL 查询:
@Query("SELECT " +
"o.geometry as geometry, " +
"o.center as center, " +
"FROM Overlay o " +
"WHERE o.layer.id = :layerId AND o.disabled = false AND o.layer.company.id = :companyId")
List<MyProjection> findWithJPQLQuery(@Param("layerId") Long layerId, @Param("companyId") Long companyId);
这两个查询都旨在从 Overlay 实体中选择数据,唯一的显著区别是第一个查询中使用了本机 SQL。
JPQL 查询按预期工作,但是当我执行本机查询并尝试从控制器向前端发送数据时,出现以下异常:
org.springframework.http.converter.HttpMessageNotWritableException: Could not write JSON: Cannot project org.geolatte.geom.Polygon to org.locationtech.jts.geom.Geometry; Target type is not an interface and no matching Converter found
具体而言,是什么原因导致了本机查询的上下文中的问题?
关于解决此问题的任何见解或建议将不胜感激。谢谢!
答: 暂无答案
评论