JPA Critera Query In Spring -


public product findproductbyid(string id , string subcategoryid) {         return em.find(product.class, id);       } 

in method pass 2 parameter. how retrieve record form product table id , subcategoryid?

actually retrieve record based on id apply subcategoryid (with , condition) error occour.

please send link explain how it's work? thanks.

public list findproductidsubcategoryidcategoryid(string categoryid, string subcategoryid,string id) { criteriabuilder cb = em.getcriteriabuilder(); criteriaquery criteria = cb.createquery(product.class); root product = criteria.from(product.class); cb.equal(product.get("subcategoryid"),subcategoryid);

    predicate csi =  cb.and(cb.equal(product.get("categoryid"), categoryid), cb.equal(product.get("subcategoryid"), subcategoryid),             cb.equal(product.get("id"), id));       criteria.select(product).where(csi);      return em.createquery(criteria).getresultlist();   } 

it's working fine , attached link http://en.wikibooks.org/wiki/java_persistence/criteria


Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -