官术网_书友最值得收藏!

  • 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.

主站蜘蛛池模板: 神木县| 肇州县| 政和县| 三明市| 柯坪县| 博乐市| 涟源市| 开鲁县| 平利县| 永清县| 宁都县| 聂荣县| 元氏县| 阜阳市| 冷水江市| 盈江县| 澜沧| 舒城县| 新巴尔虎左旗| 昌宁县| 田东县| 黑水县| 平顶山市| 佛冈县| 长丰县| 桦甸市| 古交市| 双江| 会泽县| 遵义市| 龙岩市| 喀喇| 韩城市| 宁远县| 汾西县| 南涧| 铅山县| 怀安县| 贡嘎县| 当阳市| 根河市|