Build Query with JOINS

0

I have a query run on DB2:

SELECT f.* 
       FROM Fat f 
            INNER EFat ef 
                  ON f.id = ef.id AND f.seq = ef.seq 

How do I reverse it in Java? I tried this way, but it gives error, all my classes are with their due relationships:

StringBuilder sb = new StringBuilder();
sb.append("SELECT f FROM ")
.append(getClasseGenerica().getSimpleName() + " f ")
.append(" INNER JOIN f.eFaturas ef ")   

My question is what to do, this:

ON f.id = ef.id AND f.seq = ef.seq

With this in JAVA:

.append(" AND f.id = ef.id AND f.seq = ef.seq ")
 Query query = getEntityManager().createQuery(sb.toString()); 

When I put AND or WHERE it always gives error in executing the query.

    
asked by anonymous 26.10.2018 / 17:30

1 answer

1

In JPQL it is only possible to do the inner join in the way you are trying when the classes are related (eg, Defeat Fat has an Attribute of type Efat).

Alternatively you can make the query as follows.

SELECT f 
FROM Fat f,  EFat ef 
WHERE f.id = ef.id 
    AND f.seq = ef.seq 

link

Or you can do as below:

SELECT f.* 
FROM Fat f 
    in(f.eFaturas) ef 
WHERE  f.seq = ef.seq 
    
26.10.2018 / 17:54