Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3403048
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T05:12:46+00:00 2026-05-18T05:12:46+00:00

Is is possible using Hibernate (prefferably the Criteria API) to use a mySql function

  • 0

Is is possible using Hibernate (prefferably the Criteria API) to use a mySql function to Order By.

The function I am looking to use is :-

SQRT( POW( 69.1 * ( {alias}.latitude -  51.3814282 ) , 2 ) + POW( 69.1 * (   -2.3574537 - {alias}.longitude ) * COS( {alias}.latitude / 57.3 ) , 2 ) ) 

where the {alias} is rooted at

criteria.createCriteria("location.address"); 

All I am looking to do is have the results ordered by the above distance equation, but thus far I havent found a way using the Projections options or the Order. options and am running out of ideas.

Cheers,
R

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T05:12:46+00:00Added an answer on May 18, 2026 at 5:12 am

    This doesn’t exactly answer your question but what you get out of the Criteria API is a bunch of nice Objects which adhere to their interfaces. Have you thought of lifting the ordering out of the query and instead sorting them in memory? It should be easy to express that ordering function in terms of a Comparator and then you can just sort the Collection.

    I don’t know how to express it in the .addOrder function of the Criteria API. You can add arbitrary SQL to Restrictions, but it looks like you can’t order by arbitrary SQL.

    Good luck.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I`m using hibernate with jpa, and it is configured with persistence.xml Is it possible
I am developing a java web application using hibernate as ORM. Is it possible
I am using Hibernate and got the exception ArrayIndexOutOfBoundsException. What are the possible causes?
Is it possible to limit the number of rows that are updated using Hibernate/HQL?
I am using annoted Hibernate, and I'm wondering whether the following is possible. I
Is it possible to map an enum as a string using Fluent Nhibernate?
Is it possible using StAX (specifically woodstox) to format the output xml with newlines
Is it possible using jQuery to select all <a> links which href ends with
I need to find the caller of a method. Is it possible using stacktrace
Is it possible to using paging functionality in Linq queries? Let's say I have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.