I am using the an entity that has multiple properties/table columns:
@Entity
public class History {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@NotNull
@Column
ZonedDateTime dateCreated;
@NotNull
@Column
private ZonedDateTime dateValidFrom;
...
and I have a Spring MVC controller with a handler that returns such History
entries sorted by a particular property (e.g. dateValidFrom
). The code below is from the HistoryService
:
public List<History> findAll(int page, int pageSize) {
PageRequest pageSettings = PageRequest.of(page, pageSize, Sort.by(Sort.Direction.ASC, "dateValidFrom"));
return historyRepo.findAll(pageSettings).stream().collect(Collectors.toList());
}
How can I avoid using the hardcoded dateValidFrom
property name and have a type-safe construct (detecting renaming mistakes at compile-time)?