Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I don't believe this to be the most efficient way to do this, however, it does produce the result I want</p> <pre><code>&lt;cfset matchingListings = ormExecuteQuery("Select l.ListingId from Listing l left join l.Features as featureone left join l.Features as featuretwo left join l.Features as featurethree where featureone.FeatureId = 108 and featuretwo.FeatureId = 110 and featurethree.FeatureId = 113") /&gt; </code></pre> <p>This will give me only listings that have all the features I am looking for but, it does a LOT of joining and looking at the hibernate SQL log is producing:</p> <pre><code>select listing0_.ListingId as col_0_0_ from dbo.Listing listing0_ left outer join Listing_Feature features1_ on listing0_.ListingId=features1_.ListingId left outer join dbo.Feature feature2_ on features1_.FeatureId=feature2_.FeatureId left outer join Listing_Feature features3_ on listing0_.ListingId=features3_.ListingId left outer join dbo.Feature feature4_ on features3_.FeatureId=feature4_.FeatureId left outer join Listing_Feature features5_ on listing0_.ListingId=features5_.ListingId left outer join dbo.Feature feature6_ on features5_.FeatureId=feature6_.FeatureId where 1=1 and feature2_.FeatureId=108 and feature4_.FeatureId=110 and feature6_.FeatureId=113 </code></pre> <p>It just seems like there must be a more efficient way to do this in HQL</p> <hr> <p>Jon Messer on the cf-orm-dev mailing list gave me what I believe is the most correct solution to this question posting it here for everyone:</p> <p>"As far as I know ORMExecuteQuery doesn't handle list parameters, so if you wanted to param them and return objects you'd have to do something like </p> <pre><code>&lt;cfset featureIds = [javaCast('int',108), javaCast('int',110), javaCast('int',113)] &gt; &lt;cfset q = ormGetSession().createQuery(" select l.ListingId from Listing l join l.features as f where f.FeatureId in (:features) group by l.ListingId having count(*) = #arrayLen(featureIds)# ") /&gt; &lt;cfset q.setParameterList('features', featureIds) /&gt; &lt;cfset matchingListings = q.list() /&gt; </code></pre> <p>"</p> <p>Thanks Jon!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload