title: Use PostGIS columns transparently in Hibernate
body: <p>I have a PostgreSQL table which contains, among many other columns, a spatial column <code>point</code>. This spatial column should give their contents in geoJson-Format.</p>
  
  <p>A normal SQL should look like this:</p>
  
  <pre class="lang-sql prettyprint-override"><code>select column1, column2, column3, ST_AsGeoJSON(point) from table;
  </code></pre>
  
  <p>And a writeback:</p>
  
  <pre class="lang-sql prettyprint-override"><code>update table set column1 = 'abc', column2 = 'def', column3 = 'ghi', 
    point = ST_GeomFromGeoJSON('{ ... geojson ... }') 
    where id = ??;
  </code></pre>
  
  <p>I know there is an extension for hibernate called hibernate-spatial. But this extension is for postgis 1.5 which can read geoJson, but not parse and write back geoJson to PostgreSQL. Another disadvantage: Spatial operations (like conversions) are done on server-side, not on database-side.</p>
  
  <p>Is there any possibility to inject a sql-function to a query like this:</p>
  
  <pre class="lang-java prettyprint-override"><code>EntityManager em = emFactory.createEntityManager();
  myModel selected = em.find(myModel.class, 1);
  </code></pre>
  
  <p>In myModel the used column for the geometry should be a <code>String</code> or a inherited type of String which represents a geoJson.</p>
  
  <p>I found Hibernate Dialects but it seems they work only on HQL (or JPL). I would like to use this geojson transparently - not in combination with HQL (where I forced to write SQL in code, what I don't want).</p>
  
  <p>It is also possible to use <a href="http://docs.jboss.org/hibernate/orm/4.2/javadocs/org/hibernate/mapping/Column.html#setCustomWrite(java.lang.String)" rel="nofollow"><code>setCustomWrite</code></a> and <a href="http://docs.jboss.org/hibernate/orm/4.2/javadocs/org/hibernate/mapping/Column.html#setCustomRead(java.lang.String)" rel="nofollow">setCustomRead</a> but I didn't find any examples how to use them.</p>
  
  <p>To prevent answers why I would like to leave the type in postgis-geometry - It should be left in this type because of other spatial-related operations on db-side.</p>