Hi,

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

SELECT DISTINCT c.Cert_Number, lb.id, lb.loan_Brwr_Name_First,
lb.loan_Brwr_Name_Last,                 
        lb.loan_Brwr_Name_Middle, lb.loan_Brwr_Suffix_Code,
l.Loan_Amount,l.Loan_Purpose_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
cu 

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 lb.id = :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?

Thanks
chintan

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

Reply via email to