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

  • SEARCH
  • Home
  • 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 8342929
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T05:54:28+00:00 2026-06-09T05:54:28+00:00

In mysql database I have a table named bug_list tables name: bug_list id projectId

  • 0

In mysql database I have a table named bug_list

tables name: bug_list

id    projectId    created_date  
1     5            2012-06-30 13:30:57  
2     5            2012-07-30 10:30:58  
3     5            2012-07-30 12:30:44  
4     5            2012-07-31 13:30:14  
5     5            2012-07-31 14:30:32 

I want to sort it by month (like jan, feb… ) in the first result,
sort it by week day (like mon, tue, wed) in the second result
and sort it by hour (like 2hrs range say 8-10am, 10-12pm….) in the third result

I can’t understand from criteria query. Can somebody explain how to resolve this issue?

  • 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-06-09T05:54:29+00:00Added an answer on June 9, 2026 at 5:54 am

    HERE you can find something useful.

    Start by extending Hibernate Order class:

    public class CustomizedOrderBy extends Order {
        private String sqlExpression;
    
        protected CustomizedOrderBy(String sqlExpression) {
            super(sqlExpression, true);
            this.sqlExpression = sqlExpression;
        }
    
        public String toSqlString(Criteria criteria, CriteriaQuery criteriaQuery) throws HibernateException {
            return sqlExpression;
        }
    
        public static Order sqlFormula(String sqlFormula) {
            return new CustomizedOrderBy(sqlFormula);
        }
    
        public String toString() {
            return sqlExpression;
        }
    
    }
    

    Then use some SQL formula:

    criteria.addOrder(CustomizedOrderBy.sqlFormula("MONTH("+sortBy.getInnerName()+")"+ asc));
    criteria.addOrder(CustomizedOrderBy.sqlFormula("WEEKDAY("+sortBy.getInnerName()+")"+ asc));
    criteria.addOrder(CustomizedOrderBy.sqlFormula("HOUR("+sortBy.getInnerName()+")"+ asc));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a mysql database with a table structure like below : Table Name
I have the following two tables in my mysql database. Table Name: groups id
I have 5 tables in my Mysql database with t1 with field name like
I have a MySQL database includes a table named 'Task'. and I used Hibernate
I have a calendar table in my MYSQL database with one field named datefield
In a MySQL database I have two tables linked in a join. One table
i have a table in my mysql database named (names) now everyone can save
I have a table in a MySQL database. The name of the table is
I have a mySQL database that might have a table named jason . A
I have a mysql database with a table named games and a blob field

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.