Skip to main content

Posts

Showing posts from November, 2015

JPA ordering list of entities

Example 1:   @ Entity public class Course { ... @ ManyToMany @ OrderBy ( "lastname ASC" ) public List < Student > getStudents ( ) { ... } ; ... } Example 2: @ Entity public class Student { ... @ ManyToMany ( mappedBy = "students" ) @ OrderBy // ordering by primary key is assumed public List < Course > getCourses ( ) { ... } ; ... } Example 3: @ Entity public class Person { ... @ ElementCollection @ OrderBy ( "zipcode.zip, zipcode.plusFour" ) public Set < Address > getResidences ( ) { ... } ; ... }   @ Embeddable public class Address { protected String street ; protected String city ; protected String state ; @ Embedded protected Zipcode zipcode ; }   @ Embeddable public class Zipco