我正在将现有的 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 ...
我究竟做错了什么?