Skip to content
Advertisement

JPA distinct inner join with Condition on joined table

I have two tables below:



I want to get the college object with list of students of a specific department. The SQL query is below:

So far I have tried the below JPA query but it is returning multiple College objects.

How to return a single college object with list of students with filtered department?

NOTE: I can’t alter the entity objects used here.

Advertisement

Answer

Try to use this query, using JOIN FETCH instead INNER JOIN:

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