<class name="MessageBox" table="MessageBox">
<id name="id" type="string" column="id">
<generator class="uuid"></generator>
</id>
<set name="replies" inverse="true" where="PARENT_REPLY_ID is null" fetch="join">
<key column="MESSAGEBOX_ID"/>
<one-to-many class="Reply"/>
</set>
查询出所有messageBox,并且messageBox.replies的replies要求 PARENT_REPLY_ID is null
生成的sql语句
Hibernate: select replies0_.MESSAGEBOX_ID as MESSAGEBOX5_1_1_, replies0_.id as id1_, replies0_.id as id2_0_, replies0_.title as title2_0_, replies0_.content as content2_0_, replies0_.PARENT_REPLY_ID as PARENT4_2_0_, replies0_.MESSAGEBOX_ID as MESSAGEBOX5_2_0_, replies0_.SEND_REPLY_PERSON_ID as SEND6_2_0_, replies0_.SEND_REPLY_TIME as SEND7_2_0_ from reply replies0_ where ( replies0_.PARENT_REPLY_ID is null) and replies0_.MESSAGEBOX_ID=?
如果写成
<set name="replies" inverse="true" fetch="join">
<key column="MESSAGEBOX_ID"/>
<one-to-many class="Reply"/>
</set>
就会查询所有 reply.messagebox_id=?的集合了
生成的sql语句
Hibernate: select replies0_.MESSAGEBOX_ID as MESSAGEBOX5_1_1_, replies0_.id as id1_, replies0_.id as id2_0_, replies0_.title as title2_0_, replies0_.content as content2_0_, replies0_.PARENT_REPLY_ID as PARENT4_2_0_, replies0_.MESSAGEBOX_ID as MESSAGEBOX5_2_0_, replies0_.SEND_REPLY_PERSON_ID as SEND6_2_0_, replies0_.SEND_REPLY_TIME as SEND7_2_0_ from reply replies0_ where replies0_.MESSAGEBOX_ID=?