HHH-11267 Fix JBossStandaloneJtaExampleTest
This commit is contained in:
parent
d4f240b439
commit
180f16dbae
|
@ -53,6 +53,7 @@ import org.jnp.server.NamingServer;
|
|||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* This is an example test based on http://community.jboss.org/docs/DOC-14617 that shows how to interact with
|
||||
|
@ -107,10 +108,12 @@ public class JBossStandaloneJtaExampleTest {
|
|||
ut.begin();
|
||||
try {
|
||||
Session session = sessionFactory.openSession();
|
||||
session.getTransaction().begin();
|
||||
assertTrue(session.getTransaction().isActive());
|
||||
item = new Item("anItem", "An item owned by someone");
|
||||
session.persist(item);
|
||||
session.getTransaction().commit();
|
||||
// IMO the flush should not be necessary, but session.close() does not flush
|
||||
// and the item is not persisted.
|
||||
session.flush();
|
||||
session.close();
|
||||
} catch(Exception e) {
|
||||
ut.setRollbackOnly();
|
||||
|
@ -126,7 +129,7 @@ public class JBossStandaloneJtaExampleTest {
|
|||
ut.begin();
|
||||
try {
|
||||
Session session = sessionFactory.openSession();
|
||||
session.getTransaction().begin();
|
||||
assertTrue(session.getTransaction().isActive());
|
||||
Item found = (Item) session.load(Item.class, item.getId());
|
||||
Statistics stats = session.getSessionFactory().getStatistics();
|
||||
log.info(stats.toString());
|
||||
|
@ -134,7 +137,9 @@ public class JBossStandaloneJtaExampleTest {
|
|||
assertEquals(0, stats.getSecondLevelCacheMissCount());
|
||||
assertEquals(1, stats.getSecondLevelCacheHitCount());
|
||||
session.delete(found);
|
||||
session.getTransaction().commit();
|
||||
// IMO the flush should not be necessary, but session.close() does not flush
|
||||
// and the item is not deleted.
|
||||
session.flush();
|
||||
session.close();
|
||||
} catch(Exception e) {
|
||||
ut.setRollbackOnly();
|
||||
|
@ -150,9 +155,8 @@ public class JBossStandaloneJtaExampleTest {
|
|||
ut.begin();
|
||||
try {
|
||||
Session session = sessionFactory.openSession();
|
||||
session.getTransaction().begin();
|
||||
assertTrue(session.getTransaction().isActive());
|
||||
assertNull(session.get(Item.class, item.getId()));
|
||||
session.getTransaction().commit();
|
||||
session.close();
|
||||
} catch(Exception e) {
|
||||
ut.setRollbackOnly();
|
||||
|
|
Loading…
Reference in New Issue