I don't know about with a criteria, but with hql you could do something like
this (from memory): "select p from Category c join Product p where c.Id =
:id"

On Wed, Feb 4, 2009 at 6:12 PM, Kevin <[email protected]> wrote:

>
> A coworker and I are trying to get a sense of how to best handle
> certain queries in situations where we have a many-to-many mapping
> that is exposed only on one side of the relationship.  The questions
> we had were in response to some design ideas from this article:
>
>
> http://www.udidahan.com/2009/01/24/ddd-many-to-many-object-relational-mapping/
>
> The general idea being that we have the following classes:
>
> - Two classes. Product and Category.
> - Category has a list of Products.
> - Product doesn't even know Category exists.
>
> The relationship at a database level would be implemented by a linking
> table but in our domain model we'd prefer to only expose the
> relationship in the Category class.  The question is : What is the
> best way to build a query returning all products for a given
> category?  We specifically want to have this result as some sort of
> criteria since we would like to be able to pass the criteria (actually
> a wrapper class) to other levels of the application for sorting and
> paging.
>
> At this point, we are using fluent nhibernate, automapping with a
> specific override for the category class as follows:
>
>  mappings.ForTypesThatDeriveFrom<Category>(x =>
> x.HasManyToMany<Product>(y => y.Products));
>
> In terms of possible options for querying, we've really just come up
> with using a subquery against the category to get a list of product
> IDs which can then be used with an IN clause on the products.  The
> other possibility that we considered would be to expose the
> relationship on the other end as a private or protected property.
>
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to