- 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.
推薦閱讀
- Embedded Linux Projects Using Yocto Project Cookbook
- Learning LibGDX Game Development(Second Edition)
- 嵌入式軟件系統(tǒng)測(cè)試:基于形式化方法的自動(dòng)化測(cè)試解決方案
- 編程的修煉
- SQL Server 2012數(shù)據(jù)庫技術(shù)及應(yīng)用(微課版·第5版)
- Python機(jī)器學(xué)習(xí)實(shí)戰(zhàn)
- Amazon S3 Cookbook
- JavaScript:Moving to ES2015
- 編程數(shù)學(xué)
- Learning FuelPHP for Effective PHP Development
- Python深度學(xué)習(xí):模型、方法與實(shí)現(xiàn)
- MySQL從入門到精通(軟件開發(fā)視頻大講堂)
- 動(dòng)手學(xué)數(shù)據(jù)結(jié)構(gòu)與算法
- 從零開始學(xué)Python網(wǎng)絡(luò)爬蟲
- Illustrator CS6設(shè)計(jì)與應(yīng)用任務(wù)教程