Hibernate Hql orderby problems
<p>I am using Hibernate, and I have a problem with HQL. I have users who have a latitude and longitude, and I need to compare distances between the user logged and the other users in a query and order it. What I need to do is <code>(userloged.latitude - user.latitude)^2 + (userloged.longitude - user.longitude)^2</code> in the query. I have the user logged, and I need to get the &lt; 20 nearest to him. Thanks.</p>

<pre><code>public List&lt;Usuarios&gt; getAllUsuarios(String correito, String desea) {
    // TODO Auto-generated method stub

    this.session = sf.openSession();
    Query query;
    if(desea.equals("Ambos"))
        query = session.createQuery("FROM Usuarios WHERE correo != '" + correito + "' ORDER BY ");
    else
    {
        if(desea.equals("Hombres"))
            desea = "Hombre";
        else if(desea.equals("Mujeres"))
            desea = "Mujer";
        query = session.createQuery("FROM Usuarios WHERE correo != '" + correito + "' AND genero = '" + desea + "'");
    }
    query.setMaxResults(MAX);
    List&lt;Usuarios&gt; usuarios = (List&lt;Usuarios&gt;) query.list();

    session.close();

    return usuarios;
}
</code></pre>