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

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.

主站蜘蛛池模板: 崇左市| 嵩明县| 靖江市| 金昌市| 昭觉县| 蕉岭县| 太和县| 开原市| 西青区| 咸丰县| 花莲县| 荔浦县| SHOW| 彭泽县| 繁昌县| 平塘县| 凌海市| 临高县| 偏关县| 黔江区| 泽州县| 怀集县| 兴仁县| 葫芦岛市| 垦利县| 凤凰县| 九龙坡区| 秦安县| 胶州市| 延川县| 通海县| 友谊县| 繁昌县| 营口市| 通道| 闸北区| 安泽县| 富民县| 新宁县| 开平市| 大安市|