title: Hibernate persist failure with PostGIS Geometry
body: <p>Related to <a href="https://stackoverflow.com/questions/12215212/postgis-geometry-saving-invalid-endian-flag-value-encountered/">previous question</a>. I have a Spring Roo application using Hibernate to write a Geometry object to a PostGIS database using JTS. I believe I've  fixed the problems I had in defining my Geometry object, and now Hibernate is executing its persist() method, but something is going wrong just before it hits the DB and I'm getting the exception below.</p>
  
  <p>Here are some interesting lines.  First from the Hibernate logs, the object to be persisted, and then an SQL query (presumably the ? are substituted):</p>
  
  <pre><code>...
  DEBUG org.hibernate.pretty.Printer - com.test.LandUse{id=1, centerPoint=POINT (5 6), version=0}
  ...
  DEBUG org.hibernate.SQL - insert into land_use (center_point, version, id) values (?, ?, ?)
  ...
  </code></pre>
  
  <p>Then some more things happen, though nothing obviously bad. However I don't see any 'final' SQL, and there is an attempt to roll back the transaction. Then:</p>
  
  <pre><code>org.springframework.transaction.TransactionSystemException: Could not commit JPA transaction; nested exception is javax.persistence.RollbackException: Error while committing the transaction
      at org.springframework.orm.jpa.JpaTransactionManager.doCommit(JpaTransactionManager.java:521)
      at org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:754)
      at org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:723)
      at org.springframework.transaction.interceptor.TransactionAspectSupport.commitTransactionAfterReturning(TransactionAspectSupport.java:393)
      at org.springframework.transaction.aspectj.AbstractTransactionAspect.ajc$afterReturning$org_springframework_transaction_aspectj_AbstractTransactionAspect$3$2a73e96c(AbstractTransactionAspect.aj:78)
      at com.test.LandUse_Roo_Jpa_ActiveRecord.ajc$interMethod$com_test_LandUse_Roo_Jpa_ActiveRecord$com_test_LandUse$persist(LandUse_Roo_Jpa_ActiveRecord.aj:44)
      at com.test.LandUse.persist(LandUse.java:1)
      at com.test.LandUse_Roo_Jpa_ActiveRecord.ajc$interMethodDispatch1$com_test_LandUse_Roo_Jpa_ActiveRecord$com_test_LandUse$persist(LandUse_Roo_Jpa_ActiveRecord.aj)
      at com.test.LandUseController_Roo_Controller.ajc$interMethod$com_test_LandUseController_Roo_Controller$com_test_LandUseController$create(LandUseController_Roo_Controller.aj:29)
      at com.test.LandUseController.create(LandUseController.java:1)
  ...
  Caused by: javax.persistence.RollbackException: Error while committing the transaction
  at org.hibernate.ejb.TransactionImpl.commit(TransactionImpl.java:93)
      at org.springframework.orm.jpa.JpaTransactionManager.doCommit(JpaTransactionManager.java:512)
      ... 54 more
  Caused by: java.lang.UnsupportedOperationException
      at org.hibernate.spatial.GeometrySqlTypeDescriptor.getBinder(GeometrySqlTypeDescriptor.java:52)
      at org.hibernate.type.AbstractStandardBasicType.nullSafeSet(AbstractStandardBasicType.java:283)
      at org.hibernate.type.AbstractStandardBasicType.nullSafeSet(AbstractStandardBasicType.java:278)
      at org.hibernate.type.AbstractSingleColumnStandardBasicType.nullSafeSet(AbstractSingleColumnStandardBasicType.java:89)
      at org.hibernate.persister.entity.AbstractEntityPersister.dehydrate(AbstractEntityPersister.java:2184)
      at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2430)
      at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2874)
      at org.hibernate.action.EntityInsertAction.execute(EntityInsertAction.java:79)
      at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:273)
      at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:265)
      at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:184)
      at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:321)
      at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:51)
      at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1216)
      at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:383)
      at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:133)
      at org.hibernate.ejb.TransactionImpl.commit(TransactionImpl.java:76)
      ... 55 more
  </code></pre>
  
  <p>I've been trying to get this simple use case (an object with just a single Geometry property) working for over a week now, and am about at my wits' end. If I replace the Geometry object with a String it works just fine. Does anyone know what might be causing such an error?</p>
  
  <p><strong>EDIT:</strong> Thierry's answer below got me poking through the source, and I noticed the exception is thrown in <code>GeometrySqlTypeDescriptor</code>, which has some interesting contents:</p>
  
  <pre><code>/**
   * A generic &lt;code&gt;SqlTypeDescriptor&lt;/code&gt;, intended to be remapped
   * by the spatial dialect.
   *
   * @author Karel Maesen, Geovise BVBA
   *         creation-date: 7/27/11
   */
  public class GeometrySqlTypeDescriptor implements SqlTypeDescriptor {
  
      public static final GeometrySqlTypeDescriptor INSTANCE = new GeometrySqlTypeDescriptor();
  
      @Override
      public int getSqlType() {
          return 3000; //this value doesn't conflict with presently defined java.sql.Types values.
      }
  
      @Override
      public boolean canBeRemapped() {
          return true;
      }
  
      @Override
      public &lt;X&gt; ValueBinder&lt;X&gt; getBinder(JavaTypeDescriptor&lt;X&gt; javaTypeDescriptor) {
          throw new UnsupportedOperationException();
      }
  
      @Override
      public &lt;X&gt; ValueExtractor&lt;X&gt; getExtractor(JavaTypeDescriptor&lt;X&gt; javaTypeDescriptor) {
          throw new UnsupportedOperationException();
      }
  }
  </code></pre>
  
  <p>In particular, note the class comment suggesting something is clearly wrong with the Hibernate dialect mapping. Unfortunately I have no idea what that means, but I'm guessing due to some kind of version mismatch. (Note also the declaration of SQL type 3000, as per <a href="https://stackoverflow.com/questions/12156130/hibernate-spatial-no-dialect-mapping-for-jdbc-type-3000">my previous error</a>!)</p>
  
  <p>My current dialect is <code>org.hibernate.spatial.dialect.postgis.PostgisDialect</code>, as per the <a href="http://www.hibernatespatial.org/usage.html" rel="nofollow noreferrer">Hibernate Spatial usage guide</a>. I'm using Hibernate Spatial 4.0-M1, JTS 1.12, and PostGIS 2.0.1. I'll try with a couple of different versions of PostGIS perhaps, particularly since that's the one dependency that Hibernate Spatial is supposed to provide but doesn't seem to.</p>