I'm trying to select the same fields between two tables using RIGHT JOIN... I got the error message 'Path expected for join! [select P.cin,P2.cin from com.kachafa.domain.Participant as P RIGHT JOIN ParticipantTwo as P2 ON P.cin =: P2.cin]'
name 1st data table : Participant // name 2nd data table : ParticipantTwo code as below :
public List<Participant> compareListParticipant(){
List<Participant> result = null;
try {
String jpql = "select P.cin,P2.cin from Participant as P RIGHT JOIN ParticipantTwo as P2 ON P.cin =: P2.cin" ;
Query query = entityManager.createQuery(jpql);
result = query.getResultList();
} catch (Exception e) {
e.printStackTrace();
}
return result;
}
I didnt reach to solve the problem with the JPQL join, however I i did the below method with two lists, it works for me :
private List<String> getDifference(List<String> listA, List<String> listB) {
Set<String> set = new HashSet<>(listA);
List<String> result = new ArrayList<>();
for (String element : listB) {
if (!set.contains(element)) {
result.add(element);
}
}
return result;
}