This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Object Relational Mapping and the fly likes @OrderBy annotation with simple types in JPA20 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "@OrderBy annotation with simple types in JPA20" Watch "@OrderBy annotation with simple types in JPA20" New topic
Author

@OrderBy annotation with simple types in JPA20

Michael Piotrowski
Greenhorn

Joined: Jan 09, 2012
Posts: 1
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
 
jQuery in Action, 2nd edition
 
subject: @OrderBy annotation with simple types in JPA20
 
Similar Threads
collection
Hibernate mapping collection of primitives
Collections - the meaning of ORDERED
save an array to database with hibernate
Need Some Explanation for ArrayList toString Method