171172173174175176177178179180181
transactionInfo.clear(); getLogger().info(getBundle().getString("transaction-rolledback")); } else { transaction.commit(); transactionInfo.clear(); getLogger().info(getBundle().getString("transaction-commited")); } }
170171172173174175176177178179180
8889909192939495969798
em2.joinTransaction(); em1.persist(entity1); em2.persist(entity2); transaction.commit(); em1.clear(); em2.clear(); MyEntity1 persisted1 = em1.find(MyEntity1.class, createId("id-1")); MyEntity2 persisted2 = em2.find(MyEntity2.class, createId("id-2"));
116117118119120121122123124125126
em1.joinTransaction(); em1.persist(entity1); transaction.commit(); em1.clear(); entity1 = new MyEntity1(); entity1.setId(createId("id-1")); entity1.setDescription("desc-1");
131132133134135136137138139140141
em1.joinTransaction(); em1.persist(entity1); try { transaction.commit(); Assert.fail(); } catch(TransactionException e) { e.printStackTrace(); //success
7273747576777879808182
transaction.begin(); assertTrue(transaction.isActive()); em1.persist(entity1); em2.persist(entity2); transaction.commit(); em1.clear(); em2.clear(); MyEntity1 persisted1 = em1.find(MyEntity1.class, createId("id-1")); MyEntity2 persisted2 = em2.find(MyEntity2.class, createId("id-2"));
96979899100101102103104105106
assertFalse(transaction.isActive()); transaction.begin(); assertTrue(transaction.isActive()); em1.persist(entity1); transaction.commit(); em1.clear(); entity1 = new MyEntity1(); entity1.setId(createId("id-7")); entity1.setDescription("desc-7");
110111112113114115116117118119120
assertTrue(transaction.isActive()); em1.persist(entity1); try { transaction.commit(); Assert.fail(); } catch(TransactionException te) { te.printStackTrace(); //success
178179180181182183184185186187188
EntityManager em1 = Beans.getReference(EntityManager.class, new NameQualifier("pu3")); try { em1.persist(entity1); transaction.commit(); } catch (TransactionRequiredException te) { fail("Entity Manager não ingressou em transação já em curso: " + te.getMessage()); }