直接使用sql语法去执行吧 <sql-query name="ag_mem"> <![CDATA[ select {a.*} from account a where a.accountcodehigh=:name and a.level="m" and ( a.status=:statusa or a.status=:statusb ) order by :orderby desc ]]> <return alias="a" class="com.poker.hibernate.Account"/> </sql-query>
<sql-query name="ag_mem">
<![CDATA[
select {a.*} from account a where a.accountcodehigh=:name and a.level="m" and ( a.status=:statusa or a.status=:statusb ) order by :orderby desc
]]>
<return alias="a" class="com.poker.hibernate.Account"/>
</sql-query>
hibernate应尽量避免使用联合主键,不要使用多对多,实在不行用中间表,拆成两个一对多
----------------------------------
多对多关系在某些情况下还是需要的,比如改造过去的系统等,只不过应该尽量避免