一种方法有两个查询插入和更新 @Transactional 注释

One method having two queries with insert and update with @Transactional Annotation

我有一个使用 @Transactional 注释的方法,我们在其中插入一条记录,同时我们正在为一个未更新的列更新相同的记录。当我们检查数据库时,只执行了插入查询。 示例代码:

@Transactional
public void testMethod(){

insert(Entity class); // inserting data in DB with id, processed, createdate column

update // updating processed column data for the above inserted record based on id

}

上述方法没有抛出任何错误,但是当我检查数据库时,只有插入查询成功,但更新查询没有成功。

能否请您建议如何实现上述要求?

使用查询进行更新将不起作用,因为数据库中目前还没有要更新的内容。当您使用 JPA 时,只需在验证后更新实体而不是发出查询。