【发布时间】:2019-03-12 06:41:48
【问题描述】:
我在我的 bean 上使用@OrderBy 子句,当我从持久层获取此对象时,它工作正常,但是当我尝试使用
persistedObject = saveAndFlush(MyCustomObject);
persistedObject 中的结果未按照@OrderBy 子句的指定排序。
代码sn-p:
@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);
【问题讨论】:
标签: java spring hibernate spring-data-jpa hibernate-mapping