【问题标题】:How do I UPDATE from a SELECT in JPA Custom Query如何从 JPA 自定义查询中的 SELECT 更新
【发布时间】:2021-12-27 09:26:40
【问题描述】:

我想更新 work_withdraw 表。我的目标是执行更新选择 同时功能。我想设置我的存款表挂起列 work_withdraw数量列中的数据,当用户调用更新api时

.在此处输入图片描述

我想在 work_withdraw 表数量列中设置待处理数据。 这是我的查询但我无法更新 work_withdraw 表 通过使用 JPA 查询 DepositRepository.kt

package com.nilmani.workload.repository

import com.nilmani.workload.entity.Deposit
import com.nilmani.workload.entity.WorkWithdraw
import org.springframework.data.jpa.repository.JpaRepository
import org.springframework.data.jpa.repository.Modifying
import org.springframework.data.jpa.repository.Query
import org.springframework.transaction.annotation.Transactional
import org.springframework.web.bind.annotation.RequestParam

interface DepositRepository:JpaRepository<Deposit,Long> {

    @Modifying
    @Transactional
    @Query("update Ww SET Ww .quantity = d .pending FROM WorkWithdraw AS Ww INNER JOIN  Deposit AS d  ON Ww.id = d.id")
    fun getPendingStatus(@RequestParam("id")id: WorkWithdraw):Long

}

我想在管理员进入时自动更新表 worker_withdraw worker_withdraw id 但我的查询不存在作为我想要的结果类型

【问题讨论】:

    标签: mysql spring-data-jpa


    【解决方案1】:

    JPA 不像许多 SQL 数据库那样支持更新连接语法。相反,您可以使用子查询:

    update WorkWithdraw ww
    set ww.quantity = (select d.pending from Deposit d where d.id = ww.id);
    

    【讨论】:

      猜你喜欢
      • 2016-09-17
      • 1970-01-01
      • 2015-12-07
      • 2014-11-13
      • 2014-01-08
      • 2021-09-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多