Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/hibernate/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Spring Boot JPA:@Modifying@Query无效_Java_Hibernate_Spring Boot_Spring Data Jpa_Jpql - Fatal编程技术网

Java Spring Boot JPA:@Modifying@Query无效

Java Spring Boot JPA:@Modifying@Query无效,java,hibernate,spring-boot,spring-data-jpa,jpql,Java,Hibernate,Spring Boot,Spring Data Jpa,Jpql,我试图通过执行一个请求而不是更新每个实体来提高性能。sql看起来不错,对该方法的调用已经执行,但我在hibernate日志中没有看到执行“更新” @Modifying @Query("UPDATE Order x SET x.reservedByClient = :value WHERE x.tourId = :id") public void updateReservationStatus(@Param("value") Boolean value, @Param("id") Long id)

我试图通过执行一个请求而不是更新每个实体来提高性能。sql看起来不错,对该方法的调用已经执行,但我在hibernate日志中没有看到执行“更新”

@Modifying
@Query("UPDATE Order x SET x.reservedByClient = :value WHERE x.tourId = :id")
public void updateReservationStatus(@Param("value") Boolean value, @Param("id") Long id);

有什么提示吗

修改查询应包装在事务中。尝试将
@Transactional
添加到查询中

@Modifying
@Query("UPDATE Order x SET x.reservedByClient = :value WHERE x.tourId = :id")
@Transactional
public void updateReservationStatus(@Param("value") Boolean value, @Param("id") Long id);

@事务将在服务层中使用。我们可以在存储库级别使用。如果我错了,请更正。
@Transactional
可以在两个层(服务和存储库)中使用。这取决于你想做什么,阿尼·施瓦兹沃格尔。正如Dvorog提供的解决方案。应添加符号“@Transactional”。您可以尝试依靠exeception日志自己解决问题,在这种情况下,我打赌您已经收到日志,例如执行更新/删除查询;嵌套异常为javax.persistence.TransactionRequiredException:执行更新/删除查询“,