//imports, etc.
@Entity
@Table(name = \"TSTRANS\")
@SqlResultSetMappings(
{
@SqlResultSetMapping(name = TS_TRANS_EMP_STAT
In jpa 2.1 putting @Query(nativeQuery = true)
annotation on the repository interface method, fixed the issue.
Reference:
https://github.com/spring-projects/spring-data-examples/tree/master/jpa/jpa21#support-for-custom-sqlresultsetmapping-with-constructorresult
It was a bug, now fixed: jira.spring.io/browse/DATAJPA-1280
Add:
@Query(nativeQuery=true)
at the top of a new method in the repository.
I've found one more solution: you can just remove generic from List in getStat():
@Repository
public interface TsTransRepository extends TsTransCommonRepository<TsTrans> {
List getStat(@Param("in_empid") Long aEmpid, @Param("in_gidstr") String aGidstr, @Param("in_onlytodo") Boolean aOnlytodo);
}
As others noted, this was a bug introduced in Spring Boot 2.0.0 and reported in DATAJPA-1280.
It has been fixed and released in Spring Boot 2.0.3.
There are several approaches how to fix it, mostly it is combination of different jpa and spring data features. I made some investigations and added them to issue https://jira.spring.io/browse/DATAJPA-1280. To find what you could do, please look at this project https://github.com/EugeneNik/spring-data-datajpa-1280-example and run tests to see what approaches are working fine now. Note, currently there are no way to do migration without code changes, but to my mind the simpliest way is to add class projection declaration to your repository method. Defining it you have not to change all mappings, but repositories invocations have to been changed as well. It's just another way to fix your problem:
@Repository
public interface TsTransRepository extends TsTransCommonRepository<TsTrans>
{
<T> List<T> getStat(@Param("in_empid") Long aEmpid,
@Param("in_gidstr") String aGidstr, @Param("in_onlytodo") Boolean aOnlytodo, Class<T> beanProjection);
}
Change your SqlResultSetMappings
to
@SqlResultSetMappings({
@SqlResultSetMapping(name = TS_TRANS_EMP_STAT,
columns = {
@ColumnResult(name = "EMPID", type = Long.class),
@ColumnResult(name = "CODE", type = String.class),
@ColumnResult(name = "TOTALCOUNT", type = Integer.class)
})
}
and change EmpStat
from normal class to interface:
public interface EmpStat {
Long getEMPID();
String getCODE();
Integer getTOTALCOUNT();
}