Mount Query with JOINS

Asked

Viewed 98 times

0

I have a query executed 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’s wrong, all my classes are with their proper relationships:

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

My question is to do, that:

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

With that 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 always gives error in query execution.

  • In the question there is a AND in place of ON

  • I didn’t understand what you said.

1 answer

1


  • Martian, in my case all classes are related. How could I do the way I’m trying?

  • I put another example of how to do this way, please check.

  • I tried using this way, but still giving error in creating the query.

  • Caused by: <openjpa-2.2.3-SNAPSHOT-r422266:1715851 nonfatal user error> org.apache.openjpa.persistence.Argumentexception: Found "Ef" in character 306, but expected: ["*", "+", "-", "/", "AND", "GROUP", "HAVING", "OR", "ORDER", <EOF>].

  • Can you display the wish that your system is creating ? If possible also display your entity that will make it easier to find the problem.

  • Manage to solve the problem, as it is all related to that part . append(" AND f.id = Ef.id AND f.seq = Ef.seq") you were trying to do not need, because by the mapping already does this, so just pass the final data you wanted equal reported and worked. Thanks

Show 1 more comment

Browser other questions tagged

You are not signed in. Login or sign up in order to post.