I created this two entites to demonstrate my problem:
OwnerEntity.java:
@Entity
public class OwnerEntity {
@Id
@GeneratedValue(strategy = Ge
This is a bug in Spring Data: the aliases are not detected correctly. It has also been reported here.
In QueryUtils in the applySorting method, only (outer) join aliases and function aliases with exactly one pair of parenthesis are detected. A simple alias for a property doesn't work currently.
One workaround for this is to use JpaSort.unsafe with the aliases in parenthesis when building the PageRequest, e.g.
PageRequest.of(0, 3, JpaSort.unsafe(Sort.Direction.ASC, "(name)"))
This is unsafe as the name implies, when sorting dynamically based on user input, so it should only be used for hard-coded sorting.