Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
999 views
in Technique[技术] by (71.8m points)

spring - PostGIS Geometry saving: "Invalid endian flag value encountered."

I have a Spring Roo + Hibernate project which takes a JTS well-known text (WKT) String input from the client application, converts it into a JTS Geometry object, and then attempts to write it to the PostGIS database. I had some problems with the JDBC connection and types, but these seem to have been resolved with:

@Column(columnDefinition = "Geometry", nullable = true) 
private Geometry centerPoint;

And the conversion does:

Geometry geom = new WKTReader(new GeometryFactory(new PrecisionModel(), 4326)).read(source);

However now when Hibernate tries to write my Geometry object to the database, I get an error:

2012-08-31 21:44:14,096 [tomcat-http--18] ERROR org.hibernate.util.JDBCExceptionReporter - Batch entry 0 insert into land_use (center_point, version, id) values ('<stream of 1152 bytes>', '0', '1') was aborted.  Call getNextException to see the cause.
2012-08-31 21:44:14,096 [tomcat-http--18] ERROR org.hibernate.util.JDBCExceptionReporter - ERROR: Invalid endian flag value encountered.

It seems clear that the error is related to the binary representation, which is presumably generated as a well-known binary (WKB) with some endianness. However with Hibernate hiding all the persistence away, I can't really tell which way things are going.

I've been fighting this Geometry stuff for days, and there's very little information out there on these error, so does anyone have any bright ideas? Can I specify the endianness somewhere (Hibernate or PostGIS), or perhaps store in a different format (WKT)?

EDIT: I should also mention that I'm using the newest of everything, which generally seems to be compatible:

  • Spring 3.1.1, Roo 1.2.1
  • hibernate 3.6.9
  • hibernate-spatial 4.0-M1
  • jts 1.12
  • PostgreSQL 9.1
  • postgis-jdbc 1.5.3 (not the latest, but recommended for hibernate-spatial, compiled from source)
  • postgis-jdbc 2.0.1 (just tried this now to match the version installed with PostgreSQL, same problem)

The Hibernate Spatial 4 tutorial suggests I do the property annotation as:

@Type(type="org.hibernate.spatial.GeometryType")
private Geometry centerPoint;

... but when I do this I get this other error, which the current annotation resolves.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I solve this problem adding to 'application.properties' this line:

spring.jpa.properties.hibernate.dialect=org.hibernate.spatial.dialect.postgis.PostgisDialect

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...