使用带有注释休眠

使用带有注释休眠

本文介绍了使用带有注释休眠,我想成为排序的一对多关系的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用带有注释冬眠,我希望有一个一对多的关系由创造的田野上多表进行排序。

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

  //的音符
@OneToMany
@JoinColumn(NAME =TASK_ID)
SET< TaskNote>笔记;
公开组< TaskNote> getNotes(){返回笔记;}
公共无效setNotes(SET< TaskNote>票据){this.notes =笔记;}


解决方案

因为无论答案给你完整的解决方案:

  @OneToMany
@JoinColumn(NAME =TASK_ID)
@OrderBy(创造)
清单< TaskNote>笔记;
公开名单< TaskNote> getNotes(){返回笔记;}
公共无效setNotes(列表< TaskNote>票据){this.notes =笔记;}

设置是无序的,所以使用列表,而是和你所需要的 @OrderBy 注释了。

Using hibernate with annotations, i want a one-many relationship to be sorted by the 'created' field on the 'many' table.

So far i've got this, which always ends up in a random order:

// 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;}
解决方案

since neither answer gave you the full solution :

@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;}

Set is unordered, so use List instead, and you need the @OrderBy annotation too.

这篇关于使用带有注释休眠,我想成为排序的一对多关系的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-21 04:41