当我将FindbyId与JPA一起使用时,我可以将读书设置为false
在DB复制之前设置数据库复制时,我在修改数据时遇到了问题
,我将获得要使用repository.findbyid()
进行修改的数据,然后我修改了数据。 但是我意识到repository.findbyid()
是设置@transactional(readonly = true)
in simple> simplejparepository.java
,以便我无法修改即使我在服务或repository.save()
中使用@transactional,
是否还有其他方法强制findbyid()
通过写连接连接,除非通过制作FindbyId存储库中的自定义方法?
+++) 我解决了我的问题!我想使用肮脏的检查进行修改数据,我意识到我关于EntityManagerFactory的设置是错误的,我在Spring.io中使用DOC修复了它( https://docs.spring.io/spring-data/jpa/jpa/jpa/docs/current-snaps/current-snapshot/current-snapshot/reference/reference/Reference/Reference/hhtml/#一下参考)我在许多其他开发人员发布的情况下尝试了很多次,但他们对我不起作用,但确实如此。谢谢你给我答案
I have a problem with modifying data while setting database replication
Before DB replication, I get data that I want to modify using repository.findById()
and then I modified the data.
But I realized that repository.findById()
is set @Transactional(readOnly = true)
in SimpleJpaRepository.java
so that I can't modify the data even if I use @Transactional in my Service or repository.save()
Is there any other way to force findById()
to connect by a write connection except by making custom method in the repository for findById?
+++)
I solved my problem! I wanted to use dirty checking for modifying datas and I realized that my setting about EntityManagerFactory was something wrong and I fixed it with a doc in spring.io (https://docs.spring.io/spring-data/jpa/docs/current-SNAPSHOT/reference/html/#reference) I tried many times with many other developers posting but they didn't work for me, but it did. Thank you for giving me answers ????
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
请参阅此,
-data/jpa/docs/current/reference/html/#transactions
第5.7.1节。交易查询方法是更具体的
它说@modifying注释可用于覆盖事务配置
Refer this,
https://docs.spring.io/spring-data/jpa/docs/current/reference/html/#transactions
Section 5.7.1. Transactional query methods to be more specific
It says that @Modifying annotation can be used to override transaction configuration
您无需更改该标志!
,即
中
@transactional
@modifying
@query(value =“更新用户设置点=点 +?1
id =?2“,nativequery = true)
int增加ePoints(int点,长ID);
You don't need to change that flag!
I.E.
@Transactional
@Modifying
@Query(value = "UPDATE user SET points = points + ?1
WHERE id = ?2", nativeQuery = true)
int increasePoints(int points, Long id);