当前位置:网站首页>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));
}
边栏推荐
- 2021 RoboCom 世界机器人开发者大赛-本科组初赛
- Regular expression collection
- 【必会】BM41 输出二叉树的右视图【中等+】
- 正则表达式收集
- Create Ca and issue certificate through go language
- openwrt 开启KV漫游
- SecurityUtils.getSubject().getPrincipal()为null的问题怎么解决
- 记录一下大文件上传偶然成功偶然失败问题
- PostgreSQL source code (58) tuple splicing heap_ form_ Tuple analysis
- Relatively easy to understand PID understanding
猜你喜欢
随机推荐
在代码中使用SqlCommand对象
S32Kxxx bootloader之UDS bootloader
Concepts of dictionary, hash table and array
[LeetCode] 最后一个单词的长度【58】
Is it safe to buy funds on Great Wall Securities?
Redis RDB snapshot
Y53. Chapter III kubernetes from introduction to mastery -- ingress (26)
Openwrt enable kV roaming
【ES实战】ES上的安全性运行方式
Timer和ScheduledThreadPoolExecutor的区别
algolia 搜索需求,做的快自闭了...
记录一下大文件上传偶然成功偶然失败问题
[swoole Series 1] what will you learn in the world of swoole?
Which securities company is the best to open a stock account? Is there a security guarantee
Anomaly-Transformer (ICLR 2022 Spotlight)复现过程及问题
UDS bootloader of s32kxxx bootloader
第六章 数据流建模
安全协议重点
sql 优化
RPA tutorial 01: Excel automation from introduction to practice





![[es practice] safe operation mode on ES](/img/3f/fa28783770098ff10bffeccd64fe51.png)



