• Post Reply Bookmark Topic Watch Topic
  • New Topic

@OrderBy annotation with simple types in JPA20  RSS feed

Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
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
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!