Skip to content

Commit

Permalink
HHH-11267 Fix JBossStandaloneJtaExampleTest
Browse files Browse the repository at this point in the history
  • Loading branch information
rvansa authored and Sanne committed Nov 22, 2016
1 parent d4f240b commit 180f16d
Showing 1 changed file with 10 additions and 6 deletions.
Expand Up @@ -53,6 +53,7 @@

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
Expand Down Expand Up @@ -107,10 +108,12 @@ public void testPersistAndLoadUnderJta() throws Exception {
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();
Expand All @@ -126,15 +129,17 @@ public void testPersistAndLoadUnderJta() throws Exception {
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());
assertEquals(item.getDescription(), found.getDescription());
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();
Expand All @@ -150,9 +155,8 @@ public void testPersistAndLoadUnderJta() throws Exception {
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();
Expand Down

0 comments on commit 180f16d

Please sign in to comment.