rameshsukka
asked on
Restriction class usage in Hibernate
Hi,
I am new Hibernate. Can someone help me to resolve the following issue,
I have two table with many to many relations, Product table and Group Table. Let me provide sample data
GroupId=1 Group Name= Calvin Klein Contains Product with Ids (10,11,12)
GroupId=2 Group Name= Shorts Contains Products with Ids (11,12,13,15)
GroupId=3 Group Name=Swimmers Contains products with Ids (12,17)
GroupId43 Group Name=caps Contains products with Ids (11,19,17)
I wanted to select the groups which contains common product which is also available in groups Calvin Klein and Shorts. So my Hibernate query should pick common products in groups Calvin Klein and Shorts i.e 12 and find out other group which contains product 12 i.e group name Swimmers.
I have written the Hibernate code for the same but it is returning Group 3,4 and it is not selecting common products in Group 1 and 2.
String s[]={Calvin Klein, Shorts};
DetachedCriteria detachedCriteriaForNarrowB y = DetachedCriteria.forClass( GroupDO.cl ass, "group")
.createAlias("group.produc tList", "product")
.createAlias("product.grou pList", "rootGroup")
.add(Restrictions.ne("grou p.name"," Calvin Klein "))
.add(Restrictions.ne("grou p.name"," Shorts "))
.add(Restrictions.in("root Group.name ",s));
detachedCriteriaForNarrowB y.setResul tTransform er(Criteri a.DISTINCT _ROOT_ENTI TY);
Criteria hibernateCriteria = detachedCriteriaForNarrowB y.getExecu tableCrite ria(sessio n);
Can someone help to put Restriction to select only common products in above query.
Tnx,
Sukka
I am new Hibernate. Can someone help me to resolve the following issue,
I have two table with many to many relations, Product table and Group Table. Let me provide sample data
GroupId=1 Group Name= Calvin Klein Contains Product with Ids (10,11,12)
GroupId=2 Group Name= Shorts Contains Products with Ids (11,12,13,15)
GroupId=3 Group Name=Swimmers Contains products with Ids (12,17)
GroupId43 Group Name=caps Contains products with Ids (11,19,17)
I wanted to select the groups which contains common product which is also available in groups Calvin Klein and Shorts. So my Hibernate query should pick common products in groups Calvin Klein and Shorts i.e 12 and find out other group which contains product 12 i.e group name Swimmers.
I have written the Hibernate code for the same but it is returning Group 3,4 and it is not selecting common products in Group 1 and 2.
String s[]={Calvin Klein, Shorts};
DetachedCriteria detachedCriteriaForNarrowB
.createAlias("group.produc
.createAlias("product.grou
.add(Restrictions.ne("grou
.add(Restrictions.ne("grou
.add(Restrictions.in("root
detachedCriteriaForNarrowB
Criteria hibernateCriteria = detachedCriteriaForNarrowB
Can someone help to put Restriction to select only common products in above query.
Tnx,
Sukka
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.