weixin_43952760 2019-08-24 18:17 采纳率: 0%
浏览 1046

JAVA 使用jpa原生sql查询字段 别名无值,小白求大神慷慨赐教

sql查询语句 ,其中 realPrice 是别名

 @Query(value = "select *,case when db.order_type_code = 'Db2bOrder' then d.RealTotal else  df.TotalMoney end realPrice from db2border_bill_detail db " +
            "left join db2border d on d.fID =db.source_id " +
            "left join db2brefund df on df.OrderID = db.source_id  where db.group_id = ?1 and db.db2border_bill_id = ?2", nativeQuery = true)
    List<Db2BorderBillDetail> findAllByGroupIdAndDb2BorderBillId(String groupId,Long Id);

在Db2BorderBillDetail实体类增加对应字段,这样查询正常 ,返回的realPrice的字段有值 ,但是发现保存报错 提示“Unknown column 'db2borderb0_.realPrice' in 'field list'”

    @Transient()
    private BigDecimal realPrice;

    public BigDecimal getRealPrice() {
        return realPrice;
    }

    public void setRealPrice(BigDecimal realPrice) {
        this.realPrice = realPrice;
    }

改成这样 则保存正常,但是sql查询的值就为null

    private BigDecimal realPrice;

    @Transient()
    public BigDecimal getRealPrice() {
        return realPrice;
    }

    public void setRealPrice(BigDecimal realPrice) {
        this.realPrice = realPrice;
    }

求大神赐教下,怎么才能查询保存都正常

  • 写回答

4条回答 默认 最新

  • weixin_43952760 2019-08-26 10:26
    关注
    最后还是弄多了一步操作,  查询sql 先返回List<Object[]>   再把List<Object[]>转为 List<Db2BorderBillDetail> 了
    
    评论

报告相同问题?

悬赏问题

  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?