frank
frank

Reputation: 21

how to use "st_distance" in hibernate hql and mysql 5.6.2?

I want to sort the distance using hibernate but the "st_distance" not work. the log :

----- org.hibernate.QueryException: No data type for node: org.hibernate.hql.internal.ast.tree.MethodNode -[METHOD_CALL] MethodNode: '(' +-[METHOD_NAME] IdentNode: 'st_distance' {originalText=st_distance} -[EXPR_LIST] SqlNode: 'exprList' +-[METHOD_CALL] MethodNode: '(' | +-[METHOD_NAME] IdentNode: 'POINT' {originalText=POINT} | -[EXPR_LIST] SqlNode: 'exprList' | +-[DOT] DotNode: 'facilitato0_.c_longitude' {propertyName=longitude,dereferenceType=PRIMITIVE,getPropertyPath=longitude,path={synthetic-alias}.longitude,tableAlias=facilitato0_,className=com.kingox.ins.dao.entity.Facilitator,classAlias=null} | | +-[IDENT] IdentNode: '{synthetic-alias}' {originalText={synthetic-alias}} | | -[IDENT] IdentNode: 'longitude' {originalText=longitude} | -[DOT] DotNode: 'facilitato0_.c_latitude' {propertyName=latitude,dereferenceType=PRIMITIVE,getPropertyPath=latitude,path={synthetic-alias}.latitude,tableAlias=facilitato0_,className=com.kingox.ins.dao.entity.Facilitator,classAlias=null} | +-[IDENT] IdentNode: '{synthetic-alias}' {originalText={synthetic-alias}} | -[IDENT] IdentNode: 'latitude' {originalText=latitude} -[METHOD_CALL] MethodNode: '(' +-[METHOD_NAME] IdentNode: 'POINT' {originalText=POINT} -[EXPR_LIST] SqlNode: 'exprList' +-[PARAM] ParameterNode: '?' {ordinal=0, expectedType=null} -[PARAM] ParameterNode: '?' {ordinal=1, expectedType=null} [select id, name, st_distance(POINT (longitude, latitude),POINT(?,?)) as tmpDistance

Upvotes: 2

Views: 750

Answers (2)

Carlos FTG
Carlos FTG

Reputation: 91

I have used this, and works for me

StringBuffer sb = new StringBuffer();
        sb.append("select a  from BikeStationEntity a "
                + "order by distance (a.coordinates, :userLocation) ASC");

Upvotes: 0

lexicore
lexicore

Reputation: 43661

The distance function in Hibernate Spatial is called distance, not st_distance.

But anyway Hibernate Spatial does not support distance for MySQL.

Upvotes: 2

Related Questions