diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/AbstractOneSessionTest.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/AbstractOneSessionTest.java index 2ecbba2c41..f3db035754 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/AbstractOneSessionTest.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/AbstractOneSessionTest.java @@ -8,8 +8,10 @@ import org.hibernate.MappingException; import org.hibernate.Session; import org.hibernate.SessionFactory; import org.hibernate.cfg.Configuration; +import org.hibernate.cfg.Environment; import org.hibernate.envers.AuditReader; import org.hibernate.envers.AuditReaderFactory; +import org.hibernate.test.common.ServiceRegistryHolder; import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeClass; import org.testng.annotations.BeforeMethod; @@ -27,6 +29,7 @@ public abstract class AbstractOneSessionTest { protected Configuration config; + private ServiceRegistryHolder serviceRegistryHolder; private SessionFactory sessionFactory; private Session session ; private AuditReader auditReader; @@ -45,7 +48,8 @@ public abstract class AbstractOneSessionTest { this.initMappings(); - sessionFactory = config.buildSessionFactory(); + serviceRegistryHolder = new ServiceRegistryHolder( Environment.getProperties() ); + sessionFactory = config.buildSessionFactory( serviceRegistryHolder.getServiceRegistry() ); } protected abstract void initMappings() throws MappingException, URISyntaxException ; @@ -61,7 +65,15 @@ public abstract class AbstractOneSessionTest { @AfterClass public void closeSessionFactory() { - sessionFactory.close(); + try { + sessionFactory.close(); + } + finally { + if ( serviceRegistryHolder != null ) { + serviceRegistryHolder.destroy(); + serviceRegistryHolder = null; + } + } } /**