Skip to content
Advertisement

how to fetch data from two tables in JPA

I am not able to fetch all records from two tables using the below query

I have tried this but I am getting a result from one table only. I want a result of both the tables i.e, client_software_param_mapping and client_file_configuration having the same ClientId which is a foreign key from third pojo(client_software_configuration) to first and second pojo.

first pojo

secondpojo

thirdpojo

Advertisement

Answer

this is the right query as it is returning the object of the third pojo present at that ClientId so it is able to understand the type of ClientId.JPQL never uses table and column names. It always uses entity names and their mapped fields/properties names.so here I have taken the object of the third pojo having the ClientId field.

select c,p from client_file_configuration c,client_software_param_mapping p where c.clientSoftwareConfiguration = p.clientSoftwareConfiguration

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement