• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

@OrderBy annotation with simple types in JPA20

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey,

I am preparing for JPA Certification and came across ordering issues with @ElementCollection and @OrderBy. I am reading book 'Pro JPA2' and it clearly states:

If the List is a relationship and references entities, specifying @OrderBy with no fields or properties,
or not specifying it at all, will cause the List to be ordered by the primary keys of the entities in the List.
In the case of an element collection of basic types then the List will be ordered by the values of the
elements.
Element collections of embeddable types will result in the List being defaulted to be in some
undefined order, typically in the order returned by the database in the absence of any ORDER BY clause.



Ok, it's pretty straightforward. My code.








But the result is:

String: zz
String: kk
String: jj
String: aa



So it is the input order, not 'value-based order'. I assume there should be 'aa,jj,kk,zz' order. What I am missing here? Is String not treated as simple type? I know it's an object but still - how to get ordered strings in a collection of strings? I am using Hibernate 4.1.2.Final
 
Forget Steve. Look at this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic