I have a use case requiring an IN clause to be applied for two tables.
The two tables are not related by a foreign key constraint nor are values same for any of the columns in either so to do the mapping, the query makes use of CONCAT.
The native query therefore, looks something like this:
SELECT A.requiredColumn from A, B WHERE colA LIKE CONCAT(colB, 'FOR_COMPARISON');
To do a join like this in Spring data JPA, I am not sure that there is a way to do explicit mapping since columns are not exactly "equal". These are the threads I have studied:
Selecting from Multiple Tables in Spring Data
Joining two table entities in Spring Data JPA
I applied the Spring data JPA equivalent of IN clause for the below native:
SELECT A.requiredColumn
from A
where colA in (
select CONCAT(colB, 'FOR_COMPARISON')
from B);
as:
SELECT a
from A
WHERE colA in (
select concat(
trim(colB), 'FOR_COMPARISON')
from B
);
However, this resulted in:
QuerySyntaxException: expecting CLOSE, found 'from' near line 1, column 134
Are there any thoughts to approach this problem?