Select as in hibernate
<p>How can i add <strong><em>ST_Distance(u.position, st_setsrid(st_makepoint(:lat, :lng), 4326))</em></strong> into select statement in Hibernate?</p>

<pre><code>@Query("""SELECT u FROM Driver u
    ORDER BY ST_Distance(u.position, st_setsrid(st_makepoint(:lat, :lng), 4326))
""")
fun findNearest(@Param("lat") lat: Double,
                @Param("lng") lng: Double): List&lt;Driver&gt;
</code></pre>

<p>When i try this:</p>

<pre><code>@Query("""SELECT u, ST_Distance(u.position, st_setsrid(st_makepoint(:lat, :lng), 4326)) as position FROM Driver u
    ORDER BY ST_Distance(u.position, st_setsrid(st_makepoint(:lat, :lng), 4326))
""")
fun findNearest(@Param("lat") lat: Double,
                @Param("lng") lng: Double): List&lt;Driver&gt;
</code></pre>

<p>I got the following error:</p>

<pre><code>Caused by: java.lang.IllegalStateException: 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'
       +-[DOT] DotNode: 'driver0_.position' {propertyName=position,dereferenceType=PRIMITIVE,getPropertyPath=position,path=u.position,tableAlias=driver0_,className=com.cloudtaxi.repository.entity.Driver,classAlias=u}
       |  +-[ALIAS_REF] IdentNode: 'driver0_.id' {alias=u, className=com.cloudtaxi.repository.entity.Driver, tableAlias=driver0_}
       |  \-[IDENT] IdentNode: 'position' {originalText=position}
       \-[METHOD_CALL] MethodNode: '('
          +-[METHOD_NAME] IdentNode: 'st_setsrid' {originalText=st_setsrid}
          \-[EXPR_LIST] SqlNode: 'exprList'
             +-[METHOD_CALL] MethodNode: '('
             |  +-[METHOD_NAME] IdentNode: 'st_makepoint' {originalText=st_makepoint}
             |  \-[EXPR_LIST] SqlNode: 'exprList'
             |     +-[NAMED_PARAM] ParameterNode: '?' {name=lat, expectedType=null}
             |     \-[NAMED_PARAM] ParameterNode: '?' {name=lng, expectedType=null}
             \-[NUM_INT] LiteralNode: '4326'
</code></pre>