我有以下設置:CF9 HQL語句對於很多一對多和多目標
Listing.cfc
component persistent="true"
{
property name="ListingId" column="ListingId" type="numeric" ormtype="int" fieldtype="id" generator="identity";
...
property name="Features" type="array" hint="Array of features" singularname="Feature" fieldtype="many-to-many" cfc="Feature" linktable="Listing_Feature" FKColumn="ListingId" inversejoincolumn="FeatureId";
}
Feature.cfc
component persistent="true" table="Feature" schema="dbo" output="false"
{
property name="FeatureId" column="FeatureId" type="numeric" ormtype="int" fieldtype="id" generator="identity";
property name="FeatureDescription" column="FeatureDescription" type="string" ormtype="string";
...
/*property name="Listings" fieldtype="many-to-many" cfc="Listing" linktable="Listing_Feature" fkcolumn="FeatureId" inversejoincolumn="ListingId" lazy="true" cascade="all" orderby="GroupOrder";*/
}
我可以選擇的所有目錄有一個特殊的功能使用:
<cfset matchingListings = ormExecuteQuery("from Listing l left join l.Features as feature where feature.FeatureId = :feature",{feature = 110}) />
這很好,但是,我希望能夠選擇所有具有多個功能的列表(例如,同時具有「洗碗機」和「車庫」的列表)
經過幾個小時的谷歌搜索和通過hibernate文檔查看還沒有找到一個解決方案,不會給我一個錯誤。我的猜測是,解決方案非常簡單,我只是在想它...任何人有任何建議?
至少它是正確的,我會這樣做,如果我必須留在HQL(不寫自定義,更高效的SQL) – Henry 2010-03-27 00:40:10
我已經添加了最正確的解決方案,以此答案的底部。 – 2010-03-29 20:57:11