We are using ArcSDE 10.0 to export data to the Oracle database, and the spatial property are saved using the SDE.st_geometry
format.
Now in our J2EE application we tried to manage these data by hibernate spatial.
And hs support Oracle Spatial out of box, but it have no documents about the st_geometry
for ArcSDE.
So I wonder if we can use it for st_geometry
? If not, is it possible to extend the functions of hs?
Update:
This is my dialect, and I register two functions overlaps
and length
:
public class Oracle11gSTGeometrySpatialDialect extends Oracle10gDialect {
public Oracle11gSTGeometrySpatialDialect() {
super();
registerFunction("overlaps", new STFunction(new BooleanType(), "sde.st_overlaps(?1,sde.st_geometry(?2,3))"));
registerFunction("length", new SQLFunctionTemplate(new DoubleType(), "sde.st_length(?1)"));
}
}
And the query:
Query q=em.createQuery("from HBDS h where length(h.shape) > -1");
However the generated sql is invalid:
select hbds0_.objectId as objectId1_0_, st_astext(hbds0_.shape) as shape4_0_ from TEST_BDS hbds0_ where sde.st_length(st_astext(hbds0_.shape))>-1
While the valid sql should be:
select hbds0_.objectId as objectId1_0_, st_astext(hbds0_.shape) as shape4_0_ from TEST_BDS hbds0_ where sde.st_length(hbds0_.shape)>-1
It seems that this is caused by the ColumnTransformer
annotation.
I am surprised that your example works as expected?
Now I can use the native query:
Query q = em.createNativeQuery("select st_astext(shape) from TEST_BDS h where sde.st_overlaps(h.shape, st_geometry(?,3)) = 1");
q.setParameter(1, JTS.defaultGeometryFactory.createPoint(new Coordinate(x, y)).toText());
It works, but there are some cons:
1 I have to write the select fields manually since I can not use select *
which will be a problem once I have a lot of fileds in the entity.
2 I can not count the row count for the specified query.