一個袋子,我需要得到該國名單中不包含一個國家(上IsoCode2研究)出版物如何查詢與NHibernate
SQL查詢是:
select * from pub_head ph
where not exists
(select 1 from pub_head_forbidden_country phfc , country c
where phfc.pub_head_id = ph.pub_head_id
and phfc.country_id = c.country_id
and c.iso_code2 = 'CA');
和模型:
<class name="Publication" table="PUB_HEAD">
<id name="Id" column="PUB_HEAD_ID">
<generator class="native">
<param name="sequence">SEQ_PUB_HEAD</param>
</generator>
</id>
<idbag name="Countries" table="PUB_HEAD_COUNTRY" lazy="true">
<collection-id column="PUB_HEAD_COUNTRY_ID">
<generator class="native">
<param name="sequence">SEQ_PUB_HEAD_COUNTRY</param>
</generator>
</collection-id>
<key column ="PUB_HEAD_ID" />
<many-to-many class="Model.Referential.Country, Model" column="COUNTRY_ID"/>
</idbag>
</class>
<class name="Country" table="Country">
<id name="Id" column="COUNTRY_ID">
<generator class="native">
</generator>
</id>
<property name="Name">
<column name="NAME"></column>
</property>
<property name="IsoCode2">
<column name="ISO_CODE2"></column>
</property>
<property name="IsoCode3">
<column name="ISO_CODE3"></column>
</property>
</class>
我從SubQueries開始,但我沒有成功做到這一點。
謝謝
你想要做的HQL查詢或與標準api?什麼是你發佈的SQL查詢中的pub_head_forbidden_country表? – Max 2010-12-20 17:41:20
使用條件API – Martyrian 2010-12-20 18:01:00
pub_head_forbidden_country表格與pub_head_country表格相似(對於複製/粘貼) – Martyrian 2010-12-20 18:01:40