使用带注释的hibernate,我希望对一对多的关系进行排序

Chr*_*ris 2 java annotations hibernate

使用带注释的hibernate,我希望通过'many'表上的'created'字段对一对多关系进行排序.

到目前为止,我已经得到了这个,它总是以随机顺序结束:

// The notes 
@OneToMany
@JoinColumn(name="task_id")
Set<TaskNote> notes;
public Set<TaskNote> getNotes() {return notes;}
public void setNotes(Set<TaskNote> notes) {this.notes = notes;} 
Run Code Online (Sandbox Code Playgroud)

chr*_*ris 6

既然这两个答案都没有给你完整的答案:

@OneToMany
@JoinColumn(name="task_id")
@OrderBy("created")
List<TaskNote> notes;
public List<TaskNote> getNotes() {return notes;}
public void setNotes(List<TaskNote> notes) {this.notes = notes;}
Run Code Online (Sandbox Code Playgroud)

Set是无序的,所以请List改用,你也需要@OrderBy注释.