我有這樣一個JpaRepository:執行PostGIS的功能
public interface PipeRepository extends JpaRepository<Pipe, Long> {
@Query("select p from Pipe p where st_intersects(p.geometry, ?1)=true")
Collection<Pipe> find(Geometry envelope);
@Query(value = "SELECT st_extent(p.geometry) FROM Pipe p WHERE p.id IN ?1")
Geometry getPipe(Collection<Number> id);
}
的第一個作品不錯,但在初始化過程中,第二個拋出此異常:
org.hibernate.QueryException: No data type for node: org.hibernate.hql.internal.ast.tree.MethodNode
\-[METHOD_CALL] MethodNode: '('
+-[METHOD_NAME] IdentNode: 'st_extent' {originalText=st_extent}
\-[EXPR_LIST] SqlNode: 'exprList'
\-[DOT] DotNode: 'pipe0_.geometry' {propertyName=geometry,dereferenceType=PRIMITIVE,getPropertyPath=geometry,path=p.geometry,tableAlias=pipe0_,className=es.x.model.Pipe,classAlias=p}
+-[ALIAS_REF] IdentNode: 'pipe0_.id' {alias=p, className=es.x.model.Pipe, tableAlias=pipe0_}
\-[IDENT] IdentNode: 'geometry' {originalText=geometry}
的任何暗示st_intersects
工作原因和st_extent
不工作?
更新:我認爲問題在於Spring Data JPA不能識別PostGIS函數。該集合函數(SQL的總和)正常工作:
@Query("select sum(p.id) from Pipe p where p.id in ?1")
Number getPipesSum(Collection<Number> ids);
檢查[Hibernate Spatial](http://www.hibernatespatial.org/)。 – lexicore