Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring JPA可以';t转换PostgreSQL点类型_Spring_Postgresql_Jpa_Postgis_Jinq - Fatal编程技术网

Spring JPA可以';t转换PostgreSQL点类型

Spring JPA可以';t转换PostgreSQL点类型,spring,postgresql,jpa,postgis,jinq,Spring,Postgresql,Jpa,Postgis,Jinq,我正在将现有的Spring项目转换为JPA/Jinq。我的数据库列之一是使用PostGIS几何图形点类型。我正在将该列的表映射到一个名为City的实体。这门课的内容如下: import java.io.Serializable import javax.persistence.*; import org.postgresql.geometric.PGpoint; @Entity @NamedQuery(name="City.findAll", query="SELECT c FROM City

我正在将现有的Spring项目转换为JPA/Jinq。我的数据库列之一是使用PostGIS几何图形点类型。我正在将该列的表映射到一个名为City的实体。这门课的内容如下:

import java.io.Serializable
import javax.persistence.*;
import org.postgresql.geometric.PGpoint;

@Entity
@NamedQuery(name="City.findAll", query="SELECT c FROM City c")
public class City implements Serializable {
    private static final long serialVersionUID = 1L;

    @Id
    private Integer id;

    @Column(name="location")
    private PGpoint location;

    /* constructor, getters, and setters */
}
我使用EclipseLink的反向工程功能生成了这个类,但是
位置
字段最初的类型是
对象
,它不可序列化,因此我将其更改为
PGpoint

不幸的是,当我尝试使用该类时,出现以下错误:

SEVERE: Servlet.service() for servlet [appServlet] in context with path 
[/NatureLynxV03] threw exception [Request processing failed; nested exception 
is javax.persistence.PersistenceException: Exception [EclipseLink-3002] 
(Eclipse Persistence Services - 2.6.4.v20160829-44060b6): 
org.eclipse.persistence.exceptions.ConversionException
Exception Description: The object [(-123.456,54.321)], of class 
[class org.postgresql.geometric.PGpoint], from mapping 
[org.eclipse.persistence.mappings.DirectToFieldMapping[location-->CITY.location]] 
with descriptor [RelationalDescriptor(org.abmi.naturelynx.model.City --> 
[DatabaseTable(CITY)])], could not be converted to [class [B].] with root cause
Local Exception Stack: 
Exception [EclipseLink-3002] (Eclipse Persistence Services - 2.6.4.v20160829-44060b6): 
org.eclipse.persistence.exceptions.ConversionException
Exception Description: The object [(-123.456,54.321)], of class 
[class org.postgresql.geometric.PGpoint], from mapping 
[org.eclipse.persistence.mappings.DirectToFieldMapping[location-->CITY.location]] 
with descriptor [RelationalDescriptor(org.abmi.naturelynx.model.City --> 
[DatabaseTable(CITY)])], could not be converted to [class [B]. at ...

我做错了什么?

EclipseLink支持空间类型吗?在他们的文档中哪里提到了它?我没有找到任何关于它的文档,但我确实看到了“PostgreSQL支持空间数据类型。这些可能需要自定义转换才能在JPA中使用。请参阅@StructConverter。”在本页上:。在映射到EclipseLink/JPA之前,我可能只是尝试创建一个PG视图来提取X和Y坐标。映射到视图而不是原始表是可行的,但这感觉像是一种解决方法,我不想为每个包含空间数据的表创建一个新视图。这就是为什么其他JPA提供商提供对地理空间类型的明确支持,如果你能做到这一点,答案就在这里