openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From chintan4181 <>
Subject Example of join in Criteria API
Date Wed, 20 Apr 2011 19:11:00 GMT

I have below query which i wanted to build using Criteria API

SELECT DISTINCT c.Cert_Number,, lb.loan_Brwr_Name_First,
	lb.loan_Brwr_Name_Middle, lb.loan_Brwr_Suffix_Code,
	cu.Cust_Number,b.Branch_Seq_ID, b.Branch_Check_Digit 

FROM 	Certificate c, Borrower lb, OPUS_Code oc, Loan l, Branch b, Customer

WHERE 	c.Cert_ID = lb.cert_ID 
	AND c.Cert_ID = l.Cert_ID 
	AND l.Loan_Orig_Branch_ID = b.Branch_ID 
	AND b.Branch_Cust_ID = cu.Cust_ID 
	AND lb.loan_Brwr_Seq_ID = 1 
	AND c.Cert_Current_Status_Code = oc.OPUS_Code_ID 
	AND = :newId"

I looked at the api and tried to code following way, but i could not find
way to fields on canonical metamodel classes. Are these classes generated
runtime or i have to generate first and then use?

CriteriaBuilder cb = em.getCriteriaBuilder();
		CriteriaQuery<Certificate> cq = cb.createQuery(Certificate.class);
		Metamodel m = em.getMetamodel();
		EntityType<Borrower> Brwr_ = m.entity(Borrower.class);
		EntityType<Certificate> Cert_ = m.entity(Certificate.class);
		EntityType<Loan> Loan_ = m.entity(Loan.class);
		EntityType<OPUS_Code> OPUSCode_ = m.entity(OPUS_Code.class);
		EntityType<Branch> Branch_ = m.entity(Branch.class);
		EntityType<Customer> Customer_ = m.entity(Customer.class);
		Root<Certificate> cert = cq.from(Certificate.class);
                           //here i am not able to access loan from Cert_
class which i defined above
		Join&lt;Certificate, Loan&gt; loan = cert.join(Cert_.);

can some one help me how to construct above query using criteria API?


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

View raw message