当前位置:网站首页>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));
}
边栏推荐
- Key points and difficulties of the course "information content security" at Harbin Institute of Technology
- 2022-07-01: at the annual meeting of a company, everyone is going to play a game of giving bonuses. There are a total of N employees. Each employee has construction points and trouble points. They nee
- 2021 robocom world robot developer competition - semi finals of higher vocational group
- 【ES实战】ES上的安全性运行方式
- Material design component - use bottomsheet to show extended content (I)
- Redis AOF log
- [QT] qtcreator uninstall and installation (abnormal state)
- ADO. Net SqlCommand object
- ARP报文头部格式和请求流程
- 字典、哈希表、数组的概念
猜你喜欢
[Qt] résoudre le problème que Qt msvc 2017 ne peut pas Compiler
Current situation and future development trend of Internet of things
Zero foundation tutorial of Internet of things development
写给当前及未来博士研究生一些建议整理分享
边缘计算概述
比较通俗易懂的PID理解
Chapter 6 data flow modeling
Material Design组件 - 使用BottomSheet展现扩展内容(一)
TS initial use, TS type
Redis 主从同步
随机推荐
图的遍历之深度优先搜索和广度优先搜索
有没有一段代码,让你为人类的智慧所折服
Key points and difficulties of the course "information content security" at Harbin Institute of Technology
2021 robocom world robot developer competition - preliminary competition of higher vocational group
Redis AOF日志
cookie、session、tooken
Huawei HMS core joins hands with hypergraph to inject new momentum into 3D GIS
RPA教程01:EXCEL自动化从入门到实操
2022-07-01:某公司年会上,大家要玩一食发奖金游戏,一共有n个员工, 每个员工都有建设积分和捣乱积分, 他们需要排成一队,在队伍最前面的一定是老板
URL introduction
Li Kou today's question -241 Design priorities for operational expressions
excel如何打开100万行以上的csv文件
Pytorch learning record
ADO. Net SqlDataAdapter object
2022-07-01: at the annual meeting of a company, everyone is going to play a game of giving bonuses. There are a total of N employees. Each employee has construction points and trouble points. They nee
[cmake] cmake configuration in QT Creator
Write some suggestions to current and future doctoral students to sort out and share
TS初次使用、ts类型
Timer和ScheduledThreadPoolExecutor的区别
Redis AOF log