【问题标题】:Spring Boot JPA @Query Update does not workSpring Boot JPA @Query 更新不起作用
【发布时间】:2020-05-09 06:41:12
【问题描述】:

我正在使用 Springboot,我正在尝试创建一个使用本机查询更新属性的函数

这是我界面的一部分:

@Modifying(clearAutomatically = true, flushAutomatically = true) // mandatory if native quaries are modying something in the dataBase
@Transactional
@Query("""
    update pojazd 
    set czy_zarchiwizowany = true 
    where id =: selected_id""", nativeQuery = true) 
fun archwizujPojazd(@Param("selected_id") selected_id:Long):Boolean

该功能有效。返回true,但对数据库没有影响

有什么帮助吗?

我在这里浏览了一堆类似的主题,但没有解决方案。

我会很高兴得到您的帮助。

【问题讨论】:

  • 您似乎没有收到错误,但我没想到这会与: selected_id 中的额外空间一起使用。

标签: java spring hibernate spring-boot kotlin


【解决方案1】:
@Modifying(clearAutomatically = true, flushAutomatically = true) 
@Transactional
@Query(value = "update pojazd  set czy_zarchiwizowany = true 
    where id = :selected_id", nativeQuery = true) 
fun archwizujPojazd(@Param(value="selected_id") Long selected_id);

【讨论】:

  • 我只需要将更新功能更改为无效。
【解决方案2】:

请添加“pojazd”的课程详情。可能会错过匹配名称“id”的机会。如果您浏览此博客Spring Data JPA @Modifying Annotation,将会很有帮助。

【讨论】:

    猜你喜欢
    • 2021-03-31
    • 2019-08-03
    • 1970-01-01
    • 2020-07-11
    • 2017-09-17
    • 2018-12-09
    • 1970-01-01
    • 2018-03-20
    • 2019-07-23
    相关资源
    最近更新 更多