I need to execute several different queries and I want to use the same POJO to get the results. What I get with those queries are combinations of same columns, can I reuse the same sqlResultSetMapping
?
I am working with JPA-2.1 and Java 8
My queries are something like:
select tableA.a, tableB.b, tableA.c
from tableA
inner join tableB
select tableA.a, tableB.b
from tableA
inner join tableB
select tableB.b, tableA.c
from tableA
inner join tableB
My POJO is something like:
public class Result {
String a;
String b;
String c;
}
and finally, my SqlResultSetMapping is:
@SqlResultSetMapping(
name="GeneralResult",
classes = {
@ConstructorResult(
targetClass = Result.class,
columns = {
@ColumnResult(name="a", type=String.class), @ColumnResult(name="b", type=String.class), @ColumnResult(name="c", type=String.class)
}
)
}
)
When I execute the first query, with fields a,b, the call works fine. The problem is when I execute one of the other two queries.
Can I use the same SqlResultSetMapping
for those queries?
I tried with several ConstructorResult but the problem is all fields are String (VARCHAR in DB).
Thanks in advance.