I'm using Spring Data JPA to query a User
entity that has a collection of UserGroup
s. The ordering of these groups is significant, so I've declared an @OrderColumn
on the relationship:
@Entity
public class User {
@Id
private String id;
@ManyToMany
@OrderColumn
private List<UserGroup> groups;
}
I need to query the groups for a particular user, and I want them to come back in the order specified by the @OrderColumn
in the join table. I have this query method in my UserGroupRepository
.
public Page<UserGroup> findByUsersIdContains(String userId, Pageable pageable);
That query does not honor the ordering I want. Is there something I can add to the method name, or specifying in the Sort
definition within the Pageable
, to order by the order column in the join table?