hibernate 一对多 排序 set

一个note对象下面有多个comment  显示的时候希望按comment的create date排序

在hbm.xml中这样配置

 

Xml代码  收藏代码
  1. <set name="commentses" inverse="true" lazy="false" order-by="created_date asc" >  
  2.     <key>  
  3.         <column name="note_id" />  
  4.     </key>  
  5.     <one-to-many class="com.xxx.NoteComments" />  
  6. </set>  
 

 

 


这里唯一要注意的一点是

Xml代码  收藏代码
  1. order-by="created_date asc"   的  created_date         

  是comment表中列名  而 不是comment的属性名

 引用自:http://renxiangzyq.iteye.com/blog/1050037

posted @ 2012-08-17 15:44  为伊憔悴  阅读(218)  评论(0编辑  收藏  举报