当前位置:网站首页>Operate database transactions with jpatractionmanager
Operate database transactions with jpatractionmanager
2022-07-01 23:51:00 【march of Time】
Transactions in a narrow sense refer to database transactions . It is mainly when multiple applications access the database concurrently , Transactions provide a means of isolation between these applications , To prevent the operation of each other from interfering with each other
Transactions provide a way for database operation sequence to recover from failure to normal state , At the same time, it provides a method to keep data consistency even in abnormal state .
A transaction has four characteristics , atomicity (Atomicity )、 Uniformity (Consistency )、 Isolation, (Isolation) And persistence (Durability), Referred to as transaction ACID characteristic .
use JpaTransactionManager Code to manipulate database transactions :
JpaTransactionManager transactionManager = applicationContext.getBean(JpaTransactionManager.class);
DefaultTransactionDefinition def = new DefaultTransactionDefinition();
def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW); // Isolation level of things , Start a new business , It'll be safer .
TransactionStatus status = transactionManager.getTransaction(def); // Get transaction state
Project project;
try {
...( Own business logic )
transactionManager.commit(status);
} catch (Exception e) {
transactionManager.rollback(status);
log.error("addProject error:{}", ExceptionUtils.getStackTrace(e));
throw new BusinessException(" Failed to create project group ");
}
publisher.publishEvent(new CreateProjectEvent().setProject(project));
}
边栏推荐
- 13 MySQL-约束
- UDS bootloader of s32kxxx bootloader
- How to display real-time 2D map after rviz is opened
- PyCharm调用matplotlib绘图时图像弹出问题怎么解决
- 2022年最佳智能家居开源系统:Alexa、Home Assistant、HomeKit生态系统介绍
- Resumption of attack and defense drill
- 力扣今日题-241. 为运算表达式设计优先级
- BlocProvider为什么感觉和Provider很相似?
- Applet form verification encapsulation
- 华为HMS Core携手超图为三维GIS注入新动能
猜你喜欢

【QT】对于Qt MSVC 2017无法编译的问题解决

【CMake】Qt creator 里面的 cmake 配置

.env.xxx 文件,加了常量,卻undefined

Deep learning | three concepts: epoch, batch, iteration

【QT】QtCreator卸载与安装(非正常状态)

Redis AOF日志
![[QT] solve the problem that QT MSVC 2017 cannot compile](/img/35/e458fd437a0bed4bace2d6d65c9ec8.png)
[QT] solve the problem that QT MSVC 2017 cannot compile

PyTorch学习记录

BlocProvider为什么感觉和Provider很相似?

Yunxin small class | common cognitive misunderstandings in IM and audio and video
随机推荐
[Qt] résoudre le problème que Qt msvc 2017 ne peut pas Compiler
Current situation and future development trend of Internet of things
ADO. Net SqlConnection object usage summary
记录一下大文件上传偶然成功偶然失败问题
Relatively easy to understand PID understanding
【ES实战】ES上的安全性运行方式
Why is PHP called hypertext preprocessor
Which securities company is the best to open a stock account? Is there a security guarantee
cookie、session、tooken
The third part of the construction of the defense system of offensive and defensive exercises is the establishment of a practical security system
ADO.NET之sqlCommand对象
Similarities and differences between the defined identity execution function authid determiner and PostgreSQL in Oracle
深度学习 | 三个概念:Epoch, Batch, Iteration
PyTorch学习记录
Key points of security agreement
Use vb Net to convert PNG pictures into icon type icon files
Postgresql源码(57)HOT更新为什么性能差距那么大?
[QT] test whether QT can connect to the database
JPA handwritten SQL, received with user-defined entity classes
How to display real-time 2D map after rviz is opened