title: Hibernate 5 HQL translator for Oracle Spatial
body: <p>I am upgrading an application from Hibernate 3.6.10.Final to 5.0.7.Final
  The main issue I have right now is that when before the Oracle dialect would generate a fast enough query like this : </p>
  
  <pre><code>SELECT * FROM MY_TABLE 
  WHERE SDO_RELATE(geom,SDO_GEOMETRY(?,4326),'mask=INSIDE+COVEREDBY') ='TRUE'
  </code></pre>
  
  <p>Now it will generate something terribly slow: </p>
  
  <pre><code>SELECT * FROM MY_TABLE 
  WHERE MDSYS.OGC_WITHIN(MDSYS.ST_GEOMETRY.FROM_SDO_GEOM(geom),MDSYS.ST_GEOMETRY.FROM_SDO_GEOM(?))=1 
  </code></pre>
  
  <p>This one will not finish on time and raise a transaction timeout : </p>
  
  <pre><code>JTA transaction unexpectedly rolled back (maybe due to a timeout
  </code></pre>
  
  <p>I can only think that there is something wrong with whatever dialect class it is used in order to translate HQL into proper performant Oracle spatial SQL.</p>
  
  <p>My configuration is as follows.</p>
  
  <p>pom.xml :</p>
  
  <pre><code>    &lt;dependency&gt;
          &lt;groupId&gt;org.hibernate&lt;/groupId&gt;
          &lt;artifactId&gt;hibernate-core&lt;/artifactId&gt;
          &lt;version&gt;5.0.7.Final&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.hibernate&lt;/groupId&gt;
          &lt;artifactId&gt;hibernate-entitymanager&lt;/artifactId&gt;
          &lt;version&gt;5.0.7.Final&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.hibernate&lt;/groupId&gt;
          &lt;artifactId&gt;hibernate-spatial&lt;/artifactId&gt;
          &lt;version&gt;5.0.7.Final&lt;/version&gt;
      &lt;/dependency&gt;
  </code></pre>
  
  <p>My persistence.xml , where I configure Atomikos (4.0.0M4) as transaction manager.</p>
  
  <pre><code>&lt;persistence-unit name="pers_unit_name" transaction-type="JTA"&gt;
  &lt;provider&gt;org.hibernate.ejb.HibernatePersistence&lt;/provider&gt;
  &lt;jta-data-source&gt;jta_data_source_name&lt;/jta-data-source&gt;
  &lt;mapping-file&gt;oracle.hbm.xml&lt;/mapping-file&gt;
  &lt;class&gt;...&lt;/class&gt;
  &lt;properties&gt;
          &lt;property name="hibernate.dialect" value="org.hibernate.spatial.dialect.oracle.OracleSpatial10gDialect" /&gt;
          &lt;property name="hibernate.spatial.dialect" value="org.hibernate.spatial.dialect.oracle.OracleSpatial10gDialect" /&gt;
          &lt;property name="hibernate.spatial.connection_finder" value="org.geolatte.geom.codec.db.oracle.DefaultConnectionFinder" /&gt;
          &lt;property name="hibernate.connection.autocommit" value="false" /&gt;
          &lt;property name="hibernate.transaction.manager_lookup_class" value="com.atomikos.icatch.jta.hibernate4.TransactionManagerLookup" /&gt;
           &lt;property name="transaction.factory_class"
              value="org.hibernate.transaction.JTATransactionFactory" /&gt;          
          &lt;property name="hibernate.transaction.jta.platform" value="com.atomikos.icatch.jta.hibernate4.AtomikosPlatform"/&gt; 
          &lt;property name="hibernate.transaction.coordinator_class" value="jta"/&gt;
          &lt;property name="hibernate.cache.provider_class" value="org.hibernate.cache.NoCacheProvider" /&gt;
      &lt;/properties&gt;
  &lt;/persistence-unit&gt;
  </code></pre>
  
  <p>When I debug HQLQueryPlan I see the query translator that it is using internally is : </p>
  
  <pre><code>org.hibernate.hql.internal.ast.QueryTranslatorImpl
  </code></pre>
  
  <p>Not sure whether this is right or wrong, or how this could be configured to generate the right query.</p>
  
  <p>This application is running on Tomcat 8. </p>
  
  <p>The POJO used with Hibernate to map the entity contains that geom attribute which is defined as : </p>
  
  <pre><code>@Column(name = "geom", columnDefinition="Geometry", nullable = true)
  protected Geometry geom;
  </code></pre>