开发者

Hibernate criteria for a junction table - how to create?

I have simply 3 tables like:

product

.----------

id

name

category

.----------

id

name

product_category

.----------------------

p_id

c_id

I 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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜