transactionAttributes各属性意义及配置
作者:李天傲 时间:2022-01-30 07:11:04
在使用spring提供的JpaTemplate进行查询时,如果数据量超过100 条,查询效率就会明显降低。由于开始时使用JPA内部的双向关联,造成各实体内部关联过多,从而影响所有的操作,因此怀疑是因为JPA的关联关系所致。但是去掉关联关系后的效果不显著。
配置问题。
<bean id="baseTransactionProxy" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean"
lazy-init="true" abstract="true">
<property name="transactionManager">
<ref bean="transactionManager" />
</property>
<property name="transactionAttributes">
<props>
<prop key="sav*">PROPAGATION_REQUIRED</prop>
<prop key="update*">PROPAGATION_REQUIRED</prop>
<prop key="delete*">PROPAGATION_REQUIRED</prop>
<prop key="get*">PROPAGATION_REQUIRED,readOnly</prop>
<prop key="find*">PROPAGATION_REQUIRED,readOnly</prop>
</props>
</property>
</bean>
使用上述配置,在JPA打出的日志中显示每次查询时都要进行更新操作,查阅相关spring 的资料后发现transactionAttributes的各种属性的意义如下:
事务传播行为类型 | 说明 |
PROPAGATION_REQUIRED | 如果当前没有事务,就新建一个事务,如果已经存在一个事务中,加入到这个事务中。这是最常见的选择。 |
PROPAGATION_SUPPORTS | 支持当前事务,如果当前没有事务,就以非事务方式执行。 |
PROPAGATION_MANDATORY | 使用当前的事务,如果当前没有事务,就抛出异常。 |
PROPAGATION_REQUIRES_NEW | 新建事务,如果当前存在事务,把当前事务挂起。 |
PROPAGATION_NOT_SUPPORTED | 以非事务方式执行操作,如果当前存在事务,就把当前事务挂起。 |
PROPAGATION_NEVER | 以非事务方式执行,如果当前存在事务,则抛出异常。 |
PROPAGATION_NESTED | 如果当前存在事务,则在嵌套事务内执行。如果当前没有事务,则执行与PROPAGATION_REQUIRED类似的操作。 |
来源:https://www.2cto.com/kf/201612/577472.html
标签:spring,transaction
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Android RecyclerBarChart绘制使用教程
2023-06-19 12:18:36
![](https://img.aspxhome.com/file/2023/1/83521_0s.png)
Java实现单例模式的五种方法介绍
2022-10-20 17:32:56
关于SpringBoot使用Redis空指针的问题(不能成功注入的问题)
2023-09-04 01:30:03
![](https://img.aspxhome.com/file/2023/2/61302_0s.png)
C#实现自定义单选和复选按钮样式
2022-07-22 04:01:41
![](https://img.aspxhome.com/file/2023/2/87032_0s.png)
Java获取控制台输入的两种方法小结
2023-11-29 12:40:44
Java IO异常如何处理详析
2023-12-04 21:51:29
详解c#与python的交互方式
2023-12-13 09:16:11
![](https://img.aspxhome.com/file/2023/0/72450_0s.png)
Android WebView实现顶部进度条
2023-10-14 23:44:03
![](https://img.aspxhome.com/file/2023/1/88731_0s.jpg)
新手Hadoop安装 环境搭建
2022-12-15 05:34:02
![](https://img.aspxhome.com/file/2023/2/74982_0s.jpg)
SpringBoot项目依赖和配置最新示例讲解
2021-08-13 23:04:23
java后台利用Apache poi 生成excel文档提供前台下载示例
2023-05-15 08:51:45
![](https://img.aspxhome.com/file/2023/9/75749_0s.jpg)
使用JSON.toJSONString格式化成json字符串时保留null属性
2023-05-10 14:56:34
Android 消息机制问题总结
2023-08-06 03:10:49
![](https://img.aspxhome.com/file/2023/5/84715_0s.jpg)
java实现轻量型http代理服务器示例
2021-10-05 18:14:20
详解Spring Boot微服务如何集成fescar解决分布式事务问题
2022-01-21 18:43:51
![](https://img.aspxhome.com/file/2023/1/67951_0s.png)
spring-boot-maven-plugin:打包时排除provided依赖问题
2023-07-18 02:12:11
![](https://img.aspxhome.com/file/2023/5/72545_0s.png)
MultipartResolver实现文件上传功能
2021-06-19 22:38:15
利用C#实现网络爬虫
2022-03-26 18:40:25
![](https://img.aspxhome.com/file/2023/6/72476_0s.jpg)
在Flutter中制作翻转卡片动画的完整实例代码
2023-06-23 23:31:21
SpringBoot实现过滤器、拦截器与切片的实现和区别
2023-04-28 22:51:04
![](https://img.aspxhome.com/file/2023/1/84641_0s.png)