title: PostGIS Geometry saving: "Invalid endian flag value encountered."
body: <p>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 <a href="https://stackoverflow.com/questions/12156130/hibernate-spatial-no-dialect-mapping-for-jdbc-type-3000/">the JDBC connection and types</a>, but these seem to have been resolved with:</p>
  
  <pre><code>@Column(columnDefinition = "Geometry", nullable = true) 
  private Geometry centerPoint;
  </code></pre>
  
  <p>And the conversion does:</p>
  
  <pre><code>Geometry geom = new WKTReader(new GeometryFactory(new PrecisionModel(), 4326)).read(source);
  </code></pre>
  
  <p>However now when Hibernate tries to write my Geometry object to the database, I get an error:</p>
  
  <pre><code>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 ('&lt;stream of 1152 bytes&gt;', '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.
  </code></pre>
  
  <p>It seems clear that the error is related to the binary representation, which is presumably generated as a well-known binary (WKB) with some <a href="http://edndoc.esri.com/arcsde/9.0/general_topics/wkb_representation.htm" rel="noreferrer">endianness</a>. However with Hibernate hiding all the persistence away, I can't really tell which way things are going.</p>
  
  <p>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)?</p>
  
  <p><strong>EDIT:</strong> I should also mention that I'm using the newest of everything, which generally seems to be compatible:</p>
  
  <ul>
  <li>Spring 3.1.1, Roo 1.2.1</li>
  <li>hibernate 3.6.9</li>
  <li>hibernate-spatial 4.0-M1</li>
  <li>jts 1.12</li>
  <li>PostgreSQL 9.1</li>
  <li>postgis-jdbc 1.5.3 (not the latest, but <a href="http://www.hibernatespatial.org/dependencies.html" rel="noreferrer">recommended for hibernate-spatial</a>, compiled from source)</li>
  <li>postgis-jdbc 2.0.1 (just tried this now to match the version installed with PostgreSQL, same problem)</li>
  </ul>
  
  <p>The <a href="http://www.hibernatespatial.org/tutorial-hs4.html" rel="noreferrer">Hibernate Spatial 4 tutorial</a> suggests I do the property annotation as:</p>
  
  <pre><code>@Type(type="org.hibernate.spatial.GeometryType")
  private Geometry centerPoint;
  </code></pre>
  
  <p>... but when I do this I get <a href="https://stackoverflow.com/questions/12156130/hibernate-spatial-no-dialect-mapping-for-jdbc-type-3000/">this other error</a>, which the current annotation resolves.</p>