I have the following domain objects:
@Entity
public class Item {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
private String name;
@OneToMany
private List propertyDefinitions;
}
@Entity
public class PropertyDefinition {
@Id
private Long id;
private final String name;
private final String value;
}
I would like to sort the items for example "title" named PropertyDefinition.value
How could I do that with Spring Data JPA?
Iterable items = itemRepository.findAll(new Sort("???"));
Any feedback appreciated.
解决方案
You can use the JPA or Hibernate @OrderBy annotation:
@OneToMany
@OrderBy("value ASC") // sort by value ASC
private List propertyDefinitions;
Otherwise, you can create your own query to sort them with Criteria or HQL Query.