JPA无法转换PostgreSQL POINT类型

时间:2017-03-14 21:46:26

标签: spring postgresql jpa postgis jinq

我正在将现有的Spring项目转换为JPA / Jinq。我的一个数据库列使用的是PostGIS几何POINT类型。我将该列的表映射到名为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的逆向工程功能生成了这个类,但location字段最初是Object类型,不可序列化,因此我将其更改为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 ...

我做错了什么?

0 个答案:

没有答案