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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T23:35:43+00:00 2026-05-10T23:35:43+00:00

So if my JPA query is like this: Select distinct p from Parent p

  • 0

So if my JPA query is like this: Select distinct p from Parent p left join fetch p.children order by p.someProperty

I correctly get results back ordered by p.someProperty, and I correctly get my p.children collection eagerly fetched and populated. But I’d like to have my query be something like ‘order by p.someProperty, p.children.someChildProperty’ so that the collection populated inside each parent object was sub-ordered by someChildProperty.

This seems intuitive when I think in terms of the sql that is actually generated for these calls, but I guess less so when it tries to map back to hierarchical objects.

  • 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. 2026-05-10T23:35:43+00:00Added an answer on May 10, 2026 at 11:35 pm

    For preserving order, use TreeSet. As far as, sorting of a collection inside parent is concerned, just do it in your code using Comparator.

    Well, try this on your collection definition in your parent entity class. I hope you are getting my point.

    You can use this JPA annotation,

    @javax.persistence.OrderBy(value = 'fieldName') 

    or this Hibernate specific,

    @org.hibernate.annotations.OrderBy(clause = 'FIELD_NAME asc') 

    and you can also use this,

    @org.hibernate.annotations.Sort(type = SortType.NATURAL) 

    or

    @org.hibernate.annotations.Sort(type = SortType.COMPARATOR) 

    In the case of comparator, a comparator must be in place. Other might only work with String collections.

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

Sidebar

Related Questions

Take this query: SELECT * FROM MyTable WHERE MyColumn = 'SomeValue' ORDER BY SomeFakeQualifier.MyColumn
So I have this SQL query, <named-query name=NQ::job_exists> <query> select 0 from dual where
I am using JPA namedQuery to select data from DB. @NamedQuery(name = Concept.findByRefTableNull, query
Netbean 6.9 generated the following JPA entity class from this SQL Server 2008 table:
I'm trying to evaluate the following JPQL query: select err from Error err where
I am writing a JPA QL named query that would search for documents. This
May I know how can I get the sql from a JPA query? or
Is it possible to translate the following to (Open)JPA ? select t0.* from Person
I have a some JPA entities that inherit from one another and uses discriminator
It seems like most examples of JPA/Hibernate entity bean classes I've seen do no

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.