本文主要是介绍记一次springboot jpa更新复杂几何类型报错Only simple geometries should be used,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
问题:
更新数据时,
几何字段MultiPolygon类型时报错;
java.lang.IllegalStateException: Only simple geometries should be used
几何字段Point类型时不报错;
新增时字段存在MultiPolygon不报错。
查看日志可知,并没有发送sql。可知这是框架层面的报错。
日志为
在org.hibernate.spatial.jts.JTSUtils.equals3DPrimitiveGeometries打断点可知,这方法中限定了几何类型
private static boolean equals3DPrimitiveGeometries(Geometry g1, Geometry g2) {//this method assumes that g1 and g2 are of the same typeassert ( g1.getClass().equals( g2.getClass() ) );if ( g1 instanceof Point ) {return equals3D( g1.getCoordinate(), g2.getCoordinate() );}if ( g1 instanceof LineString ) {return equalLineStringCoordinates( (LineString) g1, (LineString) g2 );}if ( g1 instanceof Polygon ) {return equalPolygonCoordinates( (Polygon) g1, (Polygon) g2 );}throw new IllegalStateException( "Only simple geometries should be used" );}
调用方法栈可知这是在org.hibernate.spatial的包下的。该方法主要实现了hibernate中检测dirty数据的功能。
当前版本为
implementation group: 'org.hibernate', name: 'hibernate-spatial', version: '5.4.32.Final'
解决办法:1.升级hibernate-spatial包;2.或手写更新sql;3.或在字段上设置@Column(name = "location",updatable=false),字段永不更新时可用。
这篇关于记一次springboot jpa更新复杂几何类型报错Only simple geometries should be used的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!