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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T02:45:50+00:00 2026-05-30T02:45:50+00:00

I tried to retrieve ordered list of elements from the database. From what I

  • 0

I tried to retrieve ordered list of elements from the database. From what I understand, @orderBy annotation should be sufficient.

It is possible to annotate two places:

field representing collection

@OrderBy
@OneToMany(cascade = CascadeType.ALL, mappedBy = Entry.REPORT_PROP)
private List<Entry> elements 

getter

@OrderBy
public List<Entry> getElements()

The problem intro
If both field and getter are annotated, the retrieved list is correctly ordered. However, if only field is annotated, the retrieved list is using database natural ordering.

The question
Does annotating only field do anything? And if not, why is it possible to annotate only field?

  • 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-30T02:45:52+00:00Added an answer on May 30, 2026 at 2:45 am

    It shouldn’t matter where you put the annotation. Depending on how you annotate, there should be three cases:

    @OneToMany(...)
    private List<Entry> elements;
    

    should mean that the list is retrieved without any particular order (your SQL database will probably return them in some ordered form, but according to the standard, it is perfectly legal if it doesn’t).

    @OrderBy
    @OneToMany(...)
    private List<Entry> elements;
    

    should retrieve the entries ordered by primary key, and

    @OrderBy("fieldname asc")
    @OneToMany(...)
    private List<Entry> elements;
    

    should retrieve the entries ordered by fieldname in ascending order, corresponding to the following JPQL statement:

    "select e from Entry e ordered by fieldname asc"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Tried examples from 'php.net' but don't understand what's the problem. Any suggestions? <?php $_SESSION['test']
I tried to retrieve the TYPE for PreProcess from DomainDB class using Type.GetType(DomainDBManager.DomainDB`1[System.String]+PreProcess) but
I'd like to retrieve the Auth= value from the multiline string below. I've tried
I need to access some data from an MS Access database and retrieve some
I just tried to retrieve a value from my mysql databade and tried to
I am using mechanize to retrieve data from many web site. When I tried
I am trying to retrieve list of files from a server with the windows
Hello i need to retrieve page source from site1.com to site2.com I tried file_getcontents
Tried to map it from Preferences -> Settings -> Keyboard, but the key combo
I am trying to retrieve the class name of an object. When I tried

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.