jpaRepository + JPQL + JOIN

1

I have query down running in my code but using the actual names of the table and fields, the same structure below works, but how do I do the same but using the JPQL language, I am using names generic table and fields just to make it easier to understand.

@Query(value = "select rc.* from tabela1 i  join tabela2 rc on rc.campoA= i.campoA")                             
public Page<Tabela2> trazerResultado(Pageable pageable);
    
asked by anonymous 19.04.2018 / 21:15

1 answer

0

Understanding that the entities Table1 and Table2 do not have a relationship with each other, and you just want to make a JOIN between them, we can do this via WHERE :

@Query(value = "SELECT tab2 FROM Tabela1 tab1, Tabela2 tab2 
    WHERE tab1.campoA = tab2.campoA")

In Hibernate's newer versions (as of 5.1) you can use ON also, making it possible to query between entities without relationship:

@Query(value = "select rc from Tabela1 tab1 
   JOIN Tabela2 rc ON rc.campoA = tab1.campoA")
    
20.05.2018 / 00:06