openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From chintan4181 <>
Subject Re: Example of join in Criteria API
Date Wed, 27 Apr 2011 23:06:25 GMT
Hi Pinaki,

i am able to gerenate dynamic query, the way you suggested. I have written
query in below format

CriteriaBuilder cb = em.getCriteriaBuilder();
		CriteriaQuery&lt;Object[]&gt; cq = cb.createQuery(Object[].class);
		Root<Certificate> cert = cq.from(Certificate.class);
		Join&lt;Certificate, Loan&gt; l = cert.join("loan");
		SetJoin&lt;Loan, Borrower&gt; lb =  l.joinSet("loanBorrowers");
		Join&lt;Loan, Branch&gt; b = l.join("branch1");
		Join&lt;Branch, Customer&gt; cu = b.join("FK__Branch__Customer");
		cq.where(cb.equal(lb.get("ssnNumber"), "ValueFromRequest"), 
				 cb.equal(lb.get("loan_Brwr_Seq_ID"), 1),
				 cb.equal(cu.get("Cust_Number"), "value_from_request"),
				 cb.equal(b.get("Branch_Check_Digit"), "value_from_request"));
		TypedQuery&lt;Object[]&gt; typedQuery = em.createQuery(cq); 
		List&lt;Object[]&gt; result = typedQuery.getResultList(); 

Now my question is: cq.where condition has all parameters values, there are
chances that user may not enter ssnNumber for search criteria. how do i put
a check so that in result query, i can not have where condition for
ssnNumber or any other parameter?


View this message in context:
Sent from the OpenJPA Users mailing list archive at

View raw message