> how can i put diffrent tables in dynamic query?
Create two separate roots for unrelated entities. This is RDBMS nomenclature
is equivalent to a cross-join.
> Customer table doesn't have relationship with Certificate table.
CriteriaBuilder cb = ...;
CriteriaQuery<Object[]> c = cb.createQuery(Object[].class);
Root<Certificate> cert = cb.from(Certificate.class);
Root<Customer> customer = cb.from(Customer.class);
c.multiselect(cert, customer);
will cross-join Certificate and Customer table unconditionally. You can, of
course, create a predicate based on some property p1 of Certificate and
another property p2 of Customer that have not expressed in domain model but
are purely based on application semantics, for example
MOD(Certificate.id,100) = Customer.age.
Another point: doing something like c.Cert_ID = lb.cert_ID where Certificate
and Borrower are related in Java domain model is *not* the recommended way
in using JPQL. If the Java model declares a relation then JPA provider will
do the required joins when the query is expressed as a navigation path. If
the application has to maintain relations as primary ids and join them
explicitly as in the posted example, it essentially defeats the purpose of
using a object-relational mapper.
I do not have the complete context of the domain model, but what I can glean
on from the example, I will suggest a query (in JPQL) as
select c from Certificate c, Customer cu
where c.loan.branch.Branch_Cust_ID = cu.Cust_ID // unrelated cross-join
and c.borrower.load_Brwr_Seq_id=1
and c.borrower.ssn = :ssn
-----
Pinaki
--
View this message in context:
http://openjpa.208410.n2.nabble.com/Example-of-join-in-Criteria-API-tp6291890p6307451.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.