Jpa执行更新sql报错 TransactionRequiredException 异常处理

jpa执行报错: Executing an update/delete query; nested exception is javax.persistence.TransactionRequiredException

更新需要添加    

    @Modifying
    @Transactional

/**
     * 冻结库存
     * @param productId
     * @param stock
     * @param freezeStock
     * @param version
     */
    @Query(value = "update Product  p set p.stock=:stock ,p.freezeStock=:freezeStock where p.productId=:productId and p.version=:version")
    @Modifying
    @Transactional
    void freezeStock(String productId, Long stock, Long freezeStock, Long version);

 

你可能感兴趣的:(常见问题汇总)