jpa投影接口出现布尔类型错误

svdrlsy4  于 2021-07-16  发布在  Java
关注(0)|答案(0)|浏览(268)

问。为什么jpa投影不能将mysql位(1)转换为java布尔值?

Springjpa投影发生错误 Projection type must be an interface! 当mysql bit(1) 类型Map到java Boolean 类型。
jpa将实体类中的布尔列转换为mysql表中的位(1)列。
如果我改变 getIsBasic 的类型 IntegerBoolean ,它不起作用。为什么会发生错误?

jpa存储库

@Query(nativeQuery=true, value="select true as isBasic from dual")
ProductOrderDto.PlanInfoProjection findPlanInfoById(Long id);

投影界面

public class ProductOrderDto {

    @Getter
    public static class PlanInfo {
        private Boolean isBasic;

        public PlanInfo(PlanInfoProjection projection) {
            // this.isBasic = projection.getIsBasic(); //<-- I want to use like this.
            if (projection.getIsBasic() == null) {
                this.isBasic = null;
            } else {
                this.isBasic = projection.getIsBasic() == 0 ? false : true;
            }
        }
    }
    public interface PlanInfoProjection {
        Integer getIsBasic();    // It works, but I have to convert Integer to Boolean to use. 
        //Boolean getIsBasic();  // doesn't work, but why???
        //Boolean isBasic();     // also doesn't work
        //boolean isBasic();     // also doesn't work
    }
}

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题