我@OrderBy
在我的 bean 上使用子句,当我从持久层获取这个对象时它工作正常,但是当我尝试使用保存这个数据时
persistedObject = saveAndFlush(MyCustomObject);
结果persistedObject
未按照@OrderBy
子句指定的方式排序。
代码片段:
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER, orphanRemoval = true)
@JoinColumn(name = "COLLECTION_ID")
@OrderBy("order ASC")
private Set<MySections> sections;
class MySections {
// Some Properties
@Column(name = "SEQ_NO")
private Integer order;
}
存储库相关代码
// this brings sections ordered by order property
collectionRepository.findById("123");
// Sections in persistedCollection are not ordered
persistedCollection = collectionRepository.saveAndFlush(collection);