最简单的方法是在配置文件中设置,利用配置文件中的order-by 属性来处理
-
<hibernate-mapping>
-
<class name="com.adcourse.form.Topics" table="tb_topics">
-
<id name="id" column="id" type="int">
-
<generator class="increment"/>
-
</id>
-
<set name="reply" order-by="datetime asc" inverse="true" cascade="all" lazy="false" >
-
<key column="topics_id"></key>
-
<one-to-many class="com.adcourse.form.Reply"/>
-
</set>
-
</class>
-
</hibernate-mapping>
-
<hibernate-mapping>
-
<class name="com.adcourse.form.Reply" table="tb_reply">
-
<id name="id" column="id" type="int">
-
<generator class="increment"/>
-
</id>
-
<property name="rdatetime" column="datetime" type="java.util.Date" not-null="true"/>
-
<many-to-one name="topic" column="topics_id" class="com.adcourse.form.Topics" />
-
</class>
-
</hibernate-mapping>
上面在一的一端查询出来的set 里面的记录根据 detetime 的升序来排列,注意:是datetime 不是rdatetime
对于注解形式,可以采用
import javax.persistence.OrderBy;
@OneToMany(cascade = { CascadeType.ALL }, fetch = FetchType.LAZY, mappedBy = "tblStudyType")
@OrderBy("lessonId ASC")
public Set<TblStudyLesson> getTblStudyLessons() {
return this.tblStudyLessons;
}
的方式来配置set的顺序