- Jakarta EE Cookbook
- Elder Moraes
- 114字
- 2021-06-24 16:12:46
How it works...
The key code line in this recipe for JTA is as follows:
<persistence-unit name="ch02-jta-pu" transaction-type="JTA">
When you use transaction-type='JTA', you are saying to the server that it should take care of all transactions made under this context. If you use RESOURCE-LOCAL instead, you are saying that you are taking care of the transactions:
@Test
public void validTransaction() throws Exception{
User user = new User(null, "Elder Moraes",
"elder@eldermoraes.com");
userBean.add(user);
user.setName("John Doe");
userBean.update(user);
User userDb = userBean.findById(1L);
assertEquals(userDb.getName(), "John Doe");
}
Each called method of UserBean starts a transaction to be completed and will run into a rollback if there's an issue while the transaction is alive. This would be committed to the end of it.
推薦閱讀
- 高手是如何做產(chǎn)品設(shè)計(jì)的(全2冊)
- 微信公眾平臺與小程序開發(fā):從零搭建整套系統(tǒng)
- 認(rèn)識編程:以Python語言講透編程的本質(zhì)
- 物聯(lián)網(wǎng)系統(tǒng)開發(fā):從0到1構(gòu)建IoT平臺(第2版)
- RSpec Essentials
- Frank Kane's Taming Big Data with Apache Spark and Python
- Fast Data Processing with Spark(Second Edition)
- JSP程序設(shè)計(jì)實(shí)例教程(第2版)
- Java程序設(shè)計(jì)教程
- WCF技術(shù)剖析(卷1)
- Drupal Search Engine Optimization
- Python數(shù)據(jù)科學(xué)實(shí)踐指南
- PHP動態(tài)網(wǎng)站開發(fā)實(shí)踐教程
- Mastering XenApp?
- Distributed Computing with Python