问题
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 :
SELECT * FROM MY_TABLE
WHERE SDO_RELATE(geom,SDO_GEOMETRY(?,4326),'mask=INSIDE+COVEREDBY') ='TRUE'
Now it will generate something terribly slow:
SELECT * FROM MY_TABLE
WHERE MDSYS.OGC_WITHIN(MDSYS.ST_GEOMETRY.FROM_SDO_GEOM(geom),MDSYS.ST_GEOMETRY.FROM_SDO_GEOM(?))=1
This one will not finish on time and raise a transaction timeout :
JTA transaction unexpectedly rolled back (maybe due to a timeout
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.
My configuration is as follows.
pom.xml :
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>5.0.7.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>5.0.7.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-spatial</artifactId>
<version>5.0.7.Final</version>
</dependency>
My persistence.xml , where I configure Atomikos (4.0.0M4) as transaction manager.
<persistence-unit name="pers_unit_name" transaction-type="JTA">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<jta-data-source>jta_data_source_name</jta-data-source>
<mapping-file>oracle.hbm.xml</mapping-file>
<class>...</class>
<properties>
<property name="hibernate.dialect" value="org.hibernate.spatial.dialect.oracle.OracleSpatial10gDialect" />
<property name="hibernate.spatial.dialect" value="org.hibernate.spatial.dialect.oracle.OracleSpatial10gDialect" />
<property name="hibernate.spatial.connection_finder" value="org.geolatte.geom.codec.db.oracle.DefaultConnectionFinder" />
<property name="hibernate.connection.autocommit" value="false" />
<property name="hibernate.transaction.manager_lookup_class" value="com.atomikos.icatch.jta.hibernate4.TransactionManagerLookup" />
<property name="transaction.factory_class"
value="org.hibernate.transaction.JTATransactionFactory" />
<property name="hibernate.transaction.jta.platform" value="com.atomikos.icatch.jta.hibernate4.AtomikosPlatform"/>
<property name="hibernate.transaction.coordinator_class" value="jta"/>
<property name="hibernate.cache.provider_class" value="org.hibernate.cache.NoCacheProvider" />
</properties>
</persistence-unit>
When I debug HQLQueryPlan I see the query translator that it is using internally is :
org.hibernate.hql.internal.ast.QueryTranslatorImpl
Not sure whether this is right or wrong, or how this could be configured to generate the right query.
This application is running on Tomcat 8.
The POJO used with Hibernate to map the entity contains that geom attribute which is defined as :
@Column(name = "geom", columnDefinition="Geometry", nullable = true)
protected Geometry geom;
回答1:
It looks that setting OGC_STRICT=false
did the trick. This tells Hibernate to use Oracle's own spatial functions are used directly, instead of using Open Geospatial compliant functions, as we can read in the OGC compliance setting documentation.
Actually, we had already set it up in the org.hibernatespatial.oracle.OracleSpatial10gDialect.properties
file, but because after the upgrade it should be named after org.hibernate.spatial.dialect.oracle.OracleSpatial10gDialect.properties
, it wouldn't work for us.
来源:https://stackoverflow.com/questions/34861793/hibernate-5-hql-translator-for-oracle-spatial