有没有办法将Point列映射到Java实体字段?
我尝试过Hibernate Spatial 4.0,但它似乎不能与没有PostGIS的纯PostgreSQL一起工作。以下是点字段定义:
import com.vividsolutions.jts.geom.Point;
...
@Column(columnDefinition = "point")
@Type(type = "org.hibernate.spatial.GeometryType")
private Point location;
Persistence.xml中的方言:
<property name="hibernate.dialect" value="org.hibernate.spatial.dialect.postgis.PostgisDialect" />
当我试图持久化这个实体时,抛出了异常:
org.postgresql.util.PSQLException: Unknown type geometry.
at org.postgresql.jdbc2.AbstractJdbc2Statement.setPGobject(AbstractJdbc2Statement.java:1603)
at org.postgresql.jdbc2.AbstractJdbc2Statement.setObject(AbstractJdbc2Statement.java:1795)
at org.postgresql.jdbc3g.AbstractJdbc3gStatement.setObject(AbstractJdbc3gStatement.java:37)
at org.postgresql.jdbc4.AbstractJdbc4Statement.setObject(AbstractJdbc4Statement.java:46)
at org.hibernate.spatial.dialect.AbstractJTSGeometryValueBinder.bind(AbstractJTSGeometryValueBinder.java:48)
at org.hibernate.spatial.dialect.AbstractJTSGeometryValueBinder.bind(AbstractJTSGeometryValueBinder.java:39)
at org.hibernate.type.AbstractStandardBasicType.nullSafeSet(AbstractStandardBasicType.java:280)
at org.hibernate.type.AbstractStandardBasicType.nullSafeSet(AbstractStandardBasicType.java:275)
at org.hibernate.type.AbstractSingleColumnStandardBasicType.nullSafeSet(AbstractSingleColumnStandardBasicType.java:57)
因此,它似乎试图将值作为PostGIS的几何类型持久化。但我只想使用简单的Point。
发布于 2014-03-17 22:01:39
你应该试着在你的数据库中设置类型为几何图形,我也没办法在mySQL中实现。几何体对于点也适用..
发布于 2014-12-16 21:10:12
由于我不能完全确定这个问题,让我先试着解释一下:
您希望将具有类型为点的字段的实体映射到类型为“com.vividsolutions.jts.geom.Point”的PostgreSQL数据库列。postgreSQL geometric types)使用hibernate,限制自己使用“标准”(即hibernate提供的)方言PostgreSQLDialect。
一些研究让我得出结论,上面提到的hibernate支持的标准方言根本不支持PostgreSQL点类型。因此,您可能希望提供自己的UserType。查看hibernate手册中的Custom types或Understanding and writing Hibernate custom user types中的博客示例。
https://stackoverflow.com/questions/22186506
复制相似问题