File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: @OrderBy annotation with simple types in JPA20
 
Similar Threads
Hibernate mapping collection of primitives
Collections - the meaning of ORDERED
collection
Need Some Explanation for ArrayList toString Method
save an array to database with hibernate