“Got different size of tuples and aliases” exception after Spring Boot 2.0.0.RELEASE migration

前端 未结 7 651
轻奢々
轻奢々 2020-12-18 20:32
//imports, etc.

@Entity
@Table(name = \"TSTRANS\")
@SqlResultSetMappings(
        {                   
                @SqlResultSetMapping(name = TS_TRANS_EMP_STAT         


        
相关标签:
7条回答
  • 2020-12-18 21:11

    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

    0 讨论(0)
  • 2020-12-18 21:11

    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.

    0 讨论(0)
  • 2020-12-18 21:14

    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);
    }
    
    0 讨论(0)
  • 2020-12-18 21:14

    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.

    0 讨论(0)
  • 2020-12-18 21:17

    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);
    
    }
    
    0 讨论(0)
  • 2020-12-18 21:27

    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();
    }
    
    0 讨论(0)
提交回复
热议问题