Hibernate criteria for a junction table - how to create?
I have simply 3 tables like:
product
.---------- id namecategory
.---------- id nameproduct_category
.---------------------- p_id c_idI want to get a list of products where the products have category of id=3.
I am confused about how to write a hibernate cr开发者_JAVA技巧iteria
for this. Any help would be appreciated.
Thanks
Criteria c = session.createCriteria(Product.class, "product");
c.createAlias("product.categories", "category");
c.add(Restrictions.eq("category.id", 3));
Check this implementation
fluent nhibernate implementation Fluent nHibernate - How to map a non-key column on a junction table?
nhibernate implementation
http://www.barebonescoder.com/2010/08/nhibernate-many-to-many-relationships/
hope this helps
精彩评论