问题描述
问。为什么 JPA Projection 无法将 MysqL bit(1)
转换为 Java Boolean
?
当 MysqL Projection type must be an interface!
类型映射到 Java bit(1)
类型时,Spring Jpa 投影发生错误 Boolean
。
Jpa 将 Entity 类中的 Boolean 列转换为 MysqL Table 中的 bit(1) 列。
如果我将 PlanInfoProjection 接口 getIsBasic
中的 Integer
类型更改为 Boolean
,它不起作用。为什么会出现错误?
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
}
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)