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 3422814
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T06:17:14+00:00 2026-05-18T06:17:14+00:00

I have several NamedQuery ‘s defined, and I’d like to be able to sort

  • 0

I have several NamedQuery‘s defined, and I’d like to be able to sort on a field for an entity dynamically, without having to create unique NamedQuery‘s for each field I want to sort on. For example:

I have an entity called MyObject, with fields ‘a’, ‘b’, and ‘c’. My base query is “SELECT DISTINCT o FROM MyObject o“, but I’d like to be able to add an ORDER BY clause to my query. Ideally, I’d be able to do something like named parameters, where my query would look like:

SELECT DISTINCT o FROM MyObject o ORDER BY :order

I would then specify the field (a, b, c) that I want to sort on. Is there any way to accomplish this using Seam/Hibernate/JPA? Is there a better strategy for tackling this?

  • 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-18T06:17:15+00:00Added an answer on May 18, 2026 at 6:17 am

    Named queries cannot be changed at run-time.

    //—– Edited-part

    public void getOrders(String orderByElement){
    
        String query = "SELECT DISTINCT o FROM MyObject o ORDER BY " + orderByElement;
    
        entityManager.createQuery(query).getResultList();
    }
    

    Its JPA specific.

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

Sidebar

Related Questions

I have several loggers defined and a root section with several appenders, something like:
I have several cron jobs and I'd like to perform some calculations on them,
I have several php scripts that have the following structures: $count = $_GET['count']; $sort
I have several models grouped in a module like this: #/app/models/blobs/small_text.rb class Blobs::SmallText <
I have several a tags as shown below on a dynamically generated page <a
I have several different user controls that get built dynamically and added to a
I have several hundred brushes defined in Application.xaml. These are shared resources for several
We have several Visual Studio projects, and we would like to: enable/disable some defines
I have several old 3.5in floppy disks that I would like to backup. My
I have several variables like these: $foo = '123'; $bar = 'bqwe'; I need

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.