Hello everyone,
we updated to Hibernate 3 and got trouble with an hql expression which
uses oracle spatial functions but worked pretty well in Hibernate 2:
Code:
select s.sectorName from SectorCoordinate s where SDO_RELATE(s.geometry,MDSYS.SDO_GEOMETRY(2007, 82027, MDSYS.SDO_POINT_TYPE(:x,:y,0), MDSYS.SDO_ELEM_INFO_ARRAY(1,1003,4),
MDSYS.SDO_ORDINATE_ARRAY(:x,:yr1,:x,:yr2,:xr,:y)), 'mask=anyinteract querytype=WINDOW')='TRUE'
The hql parser does not like the dot in MDSYS.SDO_GEOMETRY (and the others MDSYS functions).
Code:
ERROR: <AST>:0:0: unexpected AST node: .
ERROR: cs-user com.o2.gis.core.db.CurroutUtil - findSectornamesByCoor() - caught exception
org.hibernate.hql.ast.QuerySyntaxError: unexpected AST node: . [select s.sectorName from com.o2.gis.core.db.hibernate.mapping.SectorCoordinate s where SDO_RELATE(s.geometry,MDSYS.SDO_GEOMETRY(2007, 82027,MDSYS.SDO_POINT_TYPE(:x,:y,0),MDSYS.SDO_ELEM_INFO_ARRAY(1,1003,4),MDSYS.SDO_ORDINATE_ARRAY(:x,:yr1,:x,:yr2,:xr,:y)),'mask=anyinteract querytype=WINDOW')='TRUE']
at org.hibernate.hql.ast.ErrorCounter.throwQueryException(ErrorCounter.java:63)
at org.hibernate.hql.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:196)
Removing "MDSYS." lets hibernate create a nice looking SQL statement, with wrong function names, of course.
Trying to protect the dot with double-quotes or a backlash did not wrork:
Code:
org.hibernate.QueryException: unexpected char: '"' [select s.sectorName from com.o2.gis.core.db.hibernate.mapping.SectorCoordinate s where SDO_RELATE(s.geometry,"MDSYS.SDO_GEOMETRY"(2007, 82027,"MDSYS.SDO_POINT_TYPE"(:x,:y,0),"MDSYS.SDO_ELEM_INFO_ARRAY"(1,1003,4),"MDSYS.SDO_ORDINATE_ARRAY"(:x,:yr1,:x,:yr2,:xr,:y)),'mask=anyinteract querytype=WINDOW')='TRUE']
at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:165)
at org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:83)
As a workaround, we currently use the criteria api, where an sql restriction can be added. However, setting the parameters there is uglier.
Does anyone have an idea how to solve this dot problem? Might this even be a bug in the Hibernate 3 HQL parser or are there ways to protect such characters (which were not needed in Hibernate 2)?
Thanks