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

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.

主站蜘蛛池模板: 双柏县| 韩城市| 称多县| 同江市| 休宁县| 扶余县| 嵊泗县| 黑龙江省| 凌源市| 黑龙江省| 潜山县| 仪征市| 嘉峪关市| 仁寿县| 新泰市| 温宿县| 庆云县| 寿阳县| 河源市| 双鸭山市| 同心县| 当阳市| 磐石市| 隆林| 兖州市| 文成县| 错那县| 克山县| 山东省| 巴中市| 十堰市| 张家口市| 穆棱市| 万载县| 沁阳市| 中江县| 志丹县| 土默特左旗| 拉萨市| 淮安市| 吴川市|