Perfect. I knew it was something simple. Thanks!!! Todd
On Apr 1, 8:23 pm, Anne Epstein <[email protected]> wrote: > Off the top of my head, I believe the following should get you there: > > select distinct p from Product p join p.Tags t where t.TagID in(1,2,3) > > good luck! > > > > On Wed, Apr 1, 2009 at 5:21 PM, Todd <[email protected]> wrote: > > > I have a many-to-many relationship between two classes: Product and > > Tag. I need to provide functionality where I get a list of all > > products that have any one of a set of categories. I tried a simple > > HQL query like this: > > > select Product from Product inner join Tag where Tag.TagID in(1,2,3) > > > but I get a message saying that to perform outer or full joins, I must > > provide a path. But I'm trying to do an inner join. I understand > > that in the SQL world there is a relationship table that I am actually > > joining through that, but there is no object called ProductTag, so how > > do I specify that in my HQL? > > > I really don't want to pull every product and enumerate through it's > > Tags collection to build my list. Nor do I want to load each of the > > target tags and enumerate through their Products collections to find > > the intersects. There's got to be an easy way to do this that I'm > > just not grasping, yet. Any ideas out there? Below is the mapping > > XML. > > > Thanks, > > Todd > > > <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"> > > <class name="Product" table="Product"> > > <id name="ProductID" type="Int32" unsaved-value="0"> > > <column name="ProductID" sql-type="int" > > unique="true"/> > > <generator class="native" /> > > </id> > > <property name="Name" length="200" /> > > <property name="Version" length="20" /> > > <bag name="Tags" lazy="false" table="ProductTag" > > cascade="all"> > > <key column="ProductID" /> > > <many-to-many class="Tag" column="TagID" /> > > </bag> > > </class> > > </hibernate-mapping> > > > <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"> > > <class name="Tag" table="Tag"> > > <id name="TagID" type="Int32" unsaved-value="0"> > > <column name="TagID" sql-type="int" unique="true"/> > > <generator class="native" /> > > </id> > > <many-to-one name="TagType" lazy="false" column="TagTypeID" > > class="TagType" /> > > <property name="Value" length="200" /> > > </class> > > </hibernate-mapping>- Hide quoted text - > > - Show quoted text - --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "nhusers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/nhusers?hl=en -~----------~----~----~----~------~----~------~--~---
