openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From chintan4181 <chintan4...@gmail.com>
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"));
		cq.multiselect(cert.get("Cert_Number"),
lb.get("ssnNumber")).distinct(true);
		
		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?

Thanks
Chintan

--
View this message in context: http://openjpa.208410.n2.nabble.com/Example-of-join-in-Criteria-API-tp6291890p6311478.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.

Mime
View raw message