【问题标题】:how to use "st_distance" in hibernate hql and mysql 5.6.2?如何在休眠 hql 和 mysql 5.6.2 中使用“st_distance”?
【发布时间】:2018-03-19 06:58:53
【问题描述】:

我想使用休眠对距离进行排序,但“st_distance”不起作用。日志:

----- org.hibernate.QueryException: 节点没有数据类型: 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 (?,?)) 作为 tmpDistance

【问题讨论】:

  • 请格式化您的错误消息,使其可读并发布您尝试执行的代码。

标签: java hibernate hql


【解决方案1】:

Hibernate Spatial 中的距离函数称为distance,而不是st_distance

但无论如何,Hibernate Spatial does not support distance for MySQL。

【讨论】:

    【解决方案2】:

    我用过这个,对我有用

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-07-16
      • 2013-12-27
      • 1970-01-01
      • 2010-11-23
      相关资源
      最近更新 更多