我正在尝试通过嵌套集合元素的值来排序结果。我有一个非常简单的模型:
@Entity
public class User {
@Id
@NotNull
@Column(name = "userid")
private Long id;
@OneToMany(mappedBy = "user")
private Collection<Setting> settings = new HashSet<>();
// getters and setters
}
@Entity
public class Setting {
@Id
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "userid")
private User user;
private String key;
private String value;
// getters and setters
}
public interface UserRepository extends JpaRepository<User, Long>, QuerydslPredicateExecutor<User> {
}
我希望能够按照一个设置的值返回排序结果。 使用Spring Data JPA和QueryDSL,是否可以按照user.settings.value并且满足settings.name = 'SampleName'进行排序?