admin管理员组文章数量:1335380
It was interesting to read the article from Vlad Mihalcea about "Read-write and read-only transaction routing with Spring".
But still i could not direct understand what will happen in this kind of situation:
@Transactional
public Service(Repository z, Repository y) {
public void doSomething(){
z.findAllByXYZ() -> readOnly=true on repository level
z.save();
y.save();
}
}
Do we have here a problem or some disadvantages? will findAllByXYZ be fetched from the replica and the save will be processed against the primary node?
What if we dont have any replica at all, is it safe to do it like in this snippet?
It was interesting to read the article from Vlad Mihalcea about "Read-write and read-only transaction routing with Spring".
But still i could not direct understand what will happen in this kind of situation:
@Transactional
public Service(Repository z, Repository y) {
public void doSomething(){
z.findAllByXYZ() -> readOnly=true on repository level
z.save();
y.save();
}
}
Do we have here a problem or some disadvantages? will findAllByXYZ be fetched from the replica and the save will be processed against the primary node?
What if we dont have any replica at all, is it safe to do it like in this snippet?
1 Answer
Reset to default 1For your first case - this depends on the propagation
property of the Transactional
annotation. If you haven't specified this, the read-write data source will be used and all data is read from and written to the same database instance which is a good thing for data consistency. If you were to use Propagation.REQUIRES_NEW
then this would actually be using a new transaction which then would use the read only attribute and hence read from the replica.
If you don't have a replica how did you specify the datasource for the replica in the first place if you are following the example of the mentioned blog post? If it's the same as for the primary data source than this is just another jdbc connection where you might get data consistency issues since you might not read data that was previously written in the suspended transaction when using propagation REQUIRES_NEW
.
本文标签: javaJPA readOnlytrue in one big TransactionalStack Overflow
版权声明:本文标题:java - JPA: readOnly=true in one big @Transactional - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742368516a2461763.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论