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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T09:26:59+00:00 2026-06-05T09:26:59+00:00

I was reading over the docs regarding Eclipselink’s support for @OrderColumn. It looks like

  • 0

I was reading over the docs regarding Eclipselink’s support for @OrderColumn. It looks like this only applies to List and not Set. The reason I ask is because I have a ManyToMany bi-directional relationship (using a join table) which is a Set and is implemented with a HashSet because the collection can’t have duplicates.

I wanted to order the entries in this set using @OrderColumn, but it appears I can only apply this to List, however using List will break my unique requirement. Is this understanding correct?

If so what is the recommended strategy for this case?

Thanks,

-Noah

  • 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-05T09:27:00+00:00Added an answer on June 5, 2026 at 9:27 am

    This looks similar to the following question:

    Why cannot a JPA mapping attribute be a LinkedHashset?

    The Set interface does not define ordering of elements, so your set needs to be a concrete implementation like a TreeSet or LinkedHashSet implementation, not just any old Set. But your JPA provider is generally going to use its own collection implementations with special magic to handle lazy loading.

    The above answer suggests that there may be some EclipseLink-specific workaround if you are willing to give up lazy loading.

    I can think of two options, neither one perfect:

    • just use a List and rely on business logic to enforce uniqueness, with DB UNIQUE constraints as a backstop. Honestly, I end up using List for collections almost reflexively, even when Set would have been more appropriate; I admit it’s sloppy but has yet to cause any significant problems for me in years of practice.

    • use a Set and change @ManyToMany to @OneToMany, and make your join table w/order column an actual entity that implements Comparable using the order column. Then, overload your getter method to do something like

      if (! this.set instanceof TreeSet) 
         this.set = new TreeSet<T>(this.set); 
      return this.set;
      
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been searching all over SO and reading through google docs but I can't
I was reading over the documentation for query hints: http://msdn.microsoft.com/en-us/library/ms181714(SQL.90).aspx And noticed this: FAST
I was reading over this question and wondered if the accepted answer might also
I am reading over HTML5 docs on W3C site now, and I just read
I'm reading over this awesome article on friday.com. bbum shows some objective-c code and
My only experience with Flex is some limited reading over the web. What i
I've been reading over the moustache documentation, and it looks cool: https://github.com/defunkt/mustache There is
I'm having problems with a NonUniqueObjectException thrown by Hibernate. Reading the docs, and this
Reading over the responses to this question Disadvantages of Test Driven Development? I got
I've been fighting with this for a while and reading a lot of docs

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.