常见inner join
public List<Function> getRoleFunction(int rid) { return this.getHibernateTemplate().find("select f from Function as f inner join f.roles as r where r.roleid="+rid); }
使用elements 网上找的,还不懂elements具体用法??
public List<Function> getRoleFunction(int rid) { return this.getHibernateTemplate().find("select elements(r.functions) from Role as r where r.roleid=2"); }
其中role.hbm.xml
<set name="functions" table="tb_role_function" cascade="save-update" lazy="false"> <key> <column name="role_id"></column> </key> <many-to-many class="Function" column="function_id"/> </set>
function.hbm.xml
<set name="roles" table="tb_role_function" cascade="save-update" lazy="false"> <key> <column name="function_id"></column> </key> <many-to-many class="Role" column="role_id"/> </set>