hibernate 5.1空间文档尚未发布(AFAIK),我试图将具有JST几何学字段的实体持久化到PostgreSQL 9.5 +PostGIS2.2,但没有任何结果。
我还注意到hibernate-core-5.1.0中没有org.hibernate.spatial包。我尝试了以下注释的变体:
@javax.persistence.Column(name = "the_geom", columnDefinition = "Geometry")
public com.vividsolutions.jts.geom.Geometry geom;
当columnDefinition设置为" point“时,我得到"the_geom”列的类型为point,而表达式的类型为bytea“。在hibernate空间4文档中,据说5+版本不需要@Type注释,但是应该使用什么呢?如何将geom存储为有效的Postgis几何?
发布于 2016-05-08 10:25:58
在寻找了一段时间之后,我找到了一个适合我需要的解决方案(我也希望你的解决方案)。由于使用版本5,所有的jts
和geolatte
几何类型都能够由hibernate直接管理,所以您应该配置hibernate来管理这些类型。
在我的场景中,我管理spring @Configuration
类中的所有配置:在那里,如这里的“示例9”所示,我决定使用MetadataBuilder
方法如下:
@Bean
public static MetadataBuilder metadataBuilder() {
ServiceRegistry standardRegistry = new StandardServiceRegistryBuilder().build();
MetadataSources sources = new MetadataSources( standardRegistry );
return sources.getMetadataBuilder();
}
@Bean
public static MetadataBuilder spatialConfiguration() {
JTSGeometryType jtsGeometryType = new JTSGeometryType(PGGeometryTypeDescriptor.INSTANCE);
return PersistenceConfiguration.metadataBuilder().applyBasicType(jtsGeometryType);
}
这样,我的所有jts
几何图形(也有其他的geolatte
几何图形)都被正确地映射为在我的数据库模型中声明。
希望这能帮到你
达里奥。
https://stackoverflow.com/questions/36744527
复制相似问题