diff --git a/hibernate-core/src/test/java/org/hibernate/cfg/beanvalidation/ApplySchemaConstraintTest.java b/hibernate-core/src/test/java/org/hibernate/cfg/beanvalidation/ApplySchemaConstraintTest.java index f828faa878..1b0418762f 100644 --- a/hibernate-core/src/test/java/org/hibernate/cfg/beanvalidation/ApplySchemaConstraintTest.java +++ b/hibernate-core/src/test/java/org/hibernate/cfg/beanvalidation/ApplySchemaConstraintTest.java @@ -33,9 +33,12 @@ import javax.validation.constraints.Max; import javax.validation.constraints.Min; import javax.validation.constraints.NotNull; +import org.junit.AfterClass; import org.junit.Before; +import org.junit.BeforeClass; import org.junit.Test; +import org.hibernate.SessionFactory; import org.hibernate.boot.registry.BootstrapServiceRegistry; import org.hibernate.boot.registry.BootstrapServiceRegistryBuilder; import org.hibernate.boot.registry.StandardServiceRegistryBuilder; @@ -60,66 +63,77 @@ import static junit.framework.Assert.assertEquals; public class ApplySchemaConstraintTest { private StandardServiceRegistryImpl serviceRegistry; - @Before + @BeforeClass public void setUp() { serviceRegistry = createServiceRegistry(); } + @AfterClass + public void tearDown(){ + serviceRegistry.destroy(); + serviceRegistry = null; + } @Test public void testLengthConstraintApplied() throws Exception { MetadataImplementor metadata = buildMetadata( serviceRegistry, Foo.class ); - metadata.buildSessionFactory(); + SessionFactory sf= metadata.buildSessionFactory(); Column column = getColumnForAttribute( metadata.getEntityBinding( Foo.class.getName() ), "s" ); assertEquals( "@Length constraint should have been applied", 10, column.getSize().getLength() ); + sf.close(); } @Test public void testDigitsConstraintApplied() throws Exception { MetadataImplementor metadata = buildMetadata( serviceRegistry, Fubar.class ); - metadata.buildSessionFactory(); + SessionFactory sf= metadata.buildSessionFactory(); Column column = getColumnForAttribute( metadata.getEntityBinding( Fubar.class.getName() ), "f" ); Size size = column.getSize(); assertEquals( "@Digits should have been applied", 1, size.getScale() ); assertEquals( "@Digits should have been applied", 2, size.getPrecision() ); + sf.close(); } @Test public void testMinConstraintApplied() throws Exception { MetadataImplementor metadata = buildMetadata( serviceRegistry, Foobar.class ); - metadata.buildSessionFactory(); + SessionFactory sf= metadata.buildSessionFactory(); Column column = getColumnForAttribute( metadata.getEntityBinding( Foobar.class.getName() ), "i" ); assertEquals( "@Min constraint should have been applied", "i>=42", column.getCheckCondition() ); + sf.close(); } @Test public void testMaxConstraintApplied() throws Exception { MetadataImplementor metadata = buildMetadata( serviceRegistry, Snafu.class ); - metadata.buildSessionFactory(); + SessionFactory sf= metadata.buildSessionFactory(); Column column = getColumnForAttribute( metadata.getEntityBinding( Snafu.class.getName() ), "i" ); assertEquals( "@Max constraint should have been applied", "i<=42", column.getCheckCondition() ); + sf.close(); } @Test public void testSizeConstraintApplied() throws Exception { MetadataImplementor metadata = buildMetadata( serviceRegistry, Tarfu.class ); - metadata.buildSessionFactory(); + SessionFactory sf= metadata.buildSessionFactory(); Column column = getColumnForAttribute( metadata.getEntityBinding( Tarfu.class.getName() ), "s" ); Size size = column.getSize(); assertEquals( "@Size constraint should have been applied", 42, size.getLength() ); + sf.close(); } @Test public void testNotNullConstraintApplied() throws Exception { MetadataImplementor metadata = buildMetadata( serviceRegistry, Bohica.class ); - metadata.buildSessionFactory(); + SessionFactory sf= metadata.buildSessionFactory(); Column column = getColumnForAttribute( metadata.getEntityBinding( Bohica.class.getName() ), "s" ); assertEquals( "@NotNull constraint should have been applied", false, column.isNullable() ); + sf.close(); } @Test @@ -129,10 +143,11 @@ public class ApplySchemaConstraintTest { BaseClassSingleTable.class, SubClassSingleTable.class ); - metadata.buildSessionFactory(); + SessionFactory sf= metadata.buildSessionFactory(); Column column = getColumnForAttribute( metadata.getEntityBinding( SubClassSingleTable.class.getName() ), "s" ); assertEquals( "@NotNull constraint should not have been applied", true, column.isNullable() ); + sf.close(); } // TODO - Requires JoinedSubclassEntityPersister to be wired up" diff --git a/hibernate-core/src/test/java/org/hibernate/sql/TemplateTest.java b/hibernate-core/src/test/java/org/hibernate/sql/TemplateTest.java index 58e99494b1..7421f5e554 100644 --- a/hibernate-core/src/test/java/org/hibernate/sql/TemplateTest.java +++ b/hibernate-core/src/test/java/org/hibernate/sql/TemplateTest.java @@ -120,6 +120,7 @@ public class TemplateTest extends BaseUnitTestCase { public static void closeSessionFactory() { if ( SESSION_FACTORY != null ) { SESSION_FACTORY.close(); + SESSION_FACTORY = null; } } diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/SafeMappingTest.java b/hibernate-core/src/test/java/org/hibernate/test/annotations/SafeMappingTest.java index 31b5f22cda..157282a8d0 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/SafeMappingTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/annotations/SafeMappingTest.java @@ -3,6 +3,7 @@ package org.hibernate.test.annotations; import org.junit.Test; import org.hibernate.AnnotationException; +import org.hibernate.SessionFactory; import org.hibernate.cfg.Configuration; import org.hibernate.cfg.Environment; import org.hibernate.service.ServiceRegistry; @@ -20,15 +21,19 @@ public class SafeMappingTest { cfg.addAnnotatedClass( IncorrectEntity.class ); cfg.setProperty( Environment.HBM2DDL_AUTO, "create-drop" ); ServiceRegistry serviceRegistry = null; + SessionFactory sessionFactory = null; try { serviceRegistry = ServiceRegistryBuilder.buildServiceRegistry( cfg.getProperties() ); - cfg.buildSessionFactory( serviceRegistry ); + sessionFactory = cfg.buildSessionFactory( serviceRegistry ); fail( "Entity wo id should fail" ); } catch (AnnotationException e) { //success } finally { + if( sessionFactory !=null){ + sessionFactory.close(); + } if ( serviceRegistry != null ) { ServiceRegistryBuilder.destroy( serviceRegistry ); } diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/SecuredBindingTest.java b/hibernate-core/src/test/java/org/hibernate/test/annotations/SecuredBindingTest.java index 4031988180..6db7cf026f 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/SecuredBindingTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/annotations/SecuredBindingTest.java @@ -31,7 +31,7 @@ public class SecuredBindingTest { p.put( "hibernate.show_sql", "true" ); ac.setProperties( p ); ac.addAnnotatedClass( Plane.class ); - SessionFactory sf; + SessionFactory sf=null; ServiceRegistry serviceRegistry = null; try { serviceRegistry = ServiceRegistryBuilder.buildServiceRegistry( p ); @@ -47,6 +47,9 @@ public class SecuredBindingTest { //success } finally { + if(sf!=null){ + sf.close(); + } if ( serviceRegistry != null ) { ServiceRegistryBuilder.destroy( serviceRegistry ); } diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/access/jpa/AccessMappingTest.java b/hibernate-core/src/test/java/org/hibernate/test/annotations/access/jpa/AccessMappingTest.java index 2d76123644..e51245e375 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/access/jpa/AccessMappingTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/annotations/access/jpa/AccessMappingTest.java @@ -28,6 +28,7 @@ import org.junit.Before; import org.junit.Test; import org.hibernate.MappingException; +import org.hibernate.SessionFactory; import org.hibernate.cfg.AnnotationConfiguration; import org.hibernate.cfg.Environment; import org.hibernate.engine.spi.SessionFactoryImplementor; @@ -68,13 +69,18 @@ public class AccessMappingTest { AnnotationConfiguration cfg = new AnnotationConfiguration(); cfg.addAnnotatedClass( Course1.class ); cfg.addAnnotatedClass( Student.class ); + SessionFactory sf = null; try { - cfg.buildSessionFactory( serviceRegistry ); + sf= cfg.buildSessionFactory( serviceRegistry ); fail( "@Id and @OneToMany are not placed consistently in test entities. SessionFactory creation should fail." ); } catch ( MappingException e ) { // success - } + } finally { + if(sf!=null){ + sf.close(); + } + } } @Test @@ -91,6 +97,7 @@ public class AccessMappingTest { "Field access should be used.", tuplizer.getIdentifierGetter() instanceof DirectPropertyAccessor.DirectGetter ); + factory.close(); } @Test @@ -107,6 +114,7 @@ public class AccessMappingTest { "Property access should be used.", tuplizer.getIdentifierGetter() instanceof BasicPropertyAccessor.BasicGetter ); + factory.close(); } @Test @@ -123,6 +131,7 @@ public class AccessMappingTest { "Property access should be used.", tuplizer.getIdentifierGetter() instanceof BasicPropertyAccessor.BasicGetter ); + factory.close(); } @Test @@ -130,13 +139,18 @@ public class AccessMappingTest { AnnotationConfiguration cfg = new AnnotationConfiguration(); cfg.addAnnotatedClass( Course4.class ); cfg.addAnnotatedClass( Student.class ); + SessionFactory sf= null; try { - cfg.buildSessionFactory( serviceRegistry ); + sf = cfg.buildSessionFactory( serviceRegistry ); fail( "@Id and @OneToMany are not placed consistently in test entities. SessionFactory creation should fail." ); } catch ( MappingException e ) { // success - } + } finally { + if(sf!=null){ + sf.close(); + } + } } @Test @@ -158,6 +172,7 @@ public class AccessMappingTest { "Property access should be used.", tuplizer.getGetter( 0 ) instanceof BasicPropertyAccessor.BasicGetter ); + factory.close(); } @Test @@ -179,6 +194,7 @@ public class AccessMappingTest { "Property access should be used.", tuplizer.getGetter( 0 ) instanceof BasicPropertyAccessor.BasicGetter ); + factory.close(); } @Test @@ -196,6 +212,7 @@ public class AccessMappingTest { "Field access should be used since the default access mode gets inherited", tuplizer.getIdentifierGetter() instanceof DirectPropertyAccessor.DirectGetter ); + factory.close(); } @Test @@ -220,6 +237,7 @@ public class AccessMappingTest { "Field access should be used since the default access mode gets inherited", tuplizer.getGetter( 0 ) instanceof DirectPropertyAccessor.DirectGetter ); + factory.close(); } @TestForIssue(jiraKey = "HHH-5004") @@ -228,6 +246,6 @@ public class AccessMappingTest { AnnotationConfiguration cfg = new AnnotationConfiguration(); cfg.addAnnotatedClass( Course8.class ); cfg.addAnnotatedClass( Student.class ); - cfg.buildSessionFactory( serviceRegistry ); + cfg.buildSessionFactory( serviceRegistry ).close(); } } \ No newline at end of file diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/access/xml/XmlAccessTest.java b/hibernate-core/src/test/java/org/hibernate/test/annotations/access/xml/XmlAccessTest.java index e19767f483..cffeff37b0 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/access/xml/XmlAccessTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/annotations/access/xml/XmlAccessTest.java @@ -56,12 +56,13 @@ public class XmlAccessTest extends BaseUnitTestCase { // without any xml configuration we have field access assertAccessType( factory, classUnderTest, AccessType.FIELD ); - + factory.close(); // now with an additional xml configuration file changing the default access type for Tourist using basic configFiles = new ArrayList(); configFiles.add( "org/hibernate/test/annotations/access/xml/Tourist.xml" ); factory = buildSessionFactory( classes, configFiles ); assertAccessType( factory, classUnderTest, AccessType.PROPERTY ); + factory.close(); } @Test @@ -74,12 +75,13 @@ public class XmlAccessTest extends BaseUnitTestCase { // without any xml configuration we have field access assertAccessType( factory, classUnderTest, AccessType.FIELD ); - + factory.close(); // now with an additional xml configuration file changing the default access type for Tourist using persitence unit defaults configFiles = new ArrayList(); configFiles.add( "org/hibernate/test/annotations/access/xml/Tourist2.xml" ); factory = buildSessionFactory( classes, configFiles ); assertAccessType( factory, classUnderTest, AccessType.PROPERTY ); + factory.close(); } @Test @@ -92,12 +94,13 @@ public class XmlAccessTest extends BaseUnitTestCase { // without any xml configuration we have field access assertAccessType( factory, classUnderTest, AccessType.FIELD ); - + factory.close(); // now with an additional xml configuration file changing the default access type for Tourist using default in entity-mappings configFiles = new ArrayList(); configFiles.add( "org/hibernate/test/annotations/access/xml/Tourist3.xml" ); factory = buildSessionFactory( classes, configFiles ); assertAccessType( factory, classUnderTest, AccessType.PROPERTY ); + factory.close(); } @Test @@ -110,12 +113,13 @@ public class XmlAccessTest extends BaseUnitTestCase { // without any xml configuration we have field access assertAccessType( factory, classUnderTest, AccessType.FIELD ); - + factory.close(); // now with an additional xml configuration file changing the default access type for Tourist using entity level config configFiles = new ArrayList(); configFiles.add( "org/hibernate/test/annotations/access/xml/Tourist4.xml" ); factory = buildSessionFactory( classes, configFiles ); assertAccessType( factory, classUnderTest, AccessType.PROPERTY ); + factory.close(); } @Test @@ -128,6 +132,7 @@ public class XmlAccessTest extends BaseUnitTestCase { configFiles.add( "org/hibernate/test/annotations/access/xml/Crew.xml" ); SessionFactoryImplementor factory = buildSessionFactory( classes, configFiles ); assertAccessType( factory, classUnderTest, AccessType.FIELD ); + factory.close(); } @Test @@ -140,6 +145,7 @@ public class XmlAccessTest extends BaseUnitTestCase { configFiles.add( "org/hibernate/test/annotations/access/xml/RentalCar.xml" ); SessionFactoryImplementor factory = buildSessionFactory( classes, configFiles ); assertAccessType( factory, classUnderTest, AccessType.PROPERTY ); + factory.close(); } @Test @@ -152,6 +158,7 @@ public class XmlAccessTest extends BaseUnitTestCase { configFiles.add( "org/hibernate/test/annotations/access/xml/Cook.xml" ); SessionFactoryImplementor factory = buildSessionFactory( classes, configFiles ); assertAccessType( factory, classUnderTest, AccessType.PROPERTY ); + factory.close(); } @Test @@ -163,6 +170,7 @@ public class XmlAccessTest extends BaseUnitTestCase { configFiles.add( "org/hibernate/test/annotations/access/xml/Boy.xml" ); SessionFactoryImplementor factory = buildSessionFactory( classes, configFiles ); assertAccessType( factory, classUnderTest, AccessType.PROPERTY ); + factory.close(); } private SessionFactoryImplementor buildSessionFactory(List> classesUnderTest, List configFiles) { diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/collectionelement/deepcollectionelements/DeepCollectionElementTest.java b/hibernate-core/src/test/java/org/hibernate/test/annotations/collectionelement/deepcollectionelements/DeepCollectionElementTest.java index 2943763997..b40e9a3d98 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/collectionelement/deepcollectionelements/DeepCollectionElementTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/annotations/collectionelement/deepcollectionelements/DeepCollectionElementTest.java @@ -41,6 +41,6 @@ public class DeepCollectionElementTest extends BaseUnitTestCase { configuration.addAnnotatedClass( A.class ); configuration.addAnnotatedClass( B.class ); configuration.addAnnotatedClass( C.class ); - configuration.buildSessionFactory( ServiceRegistryBuilder.buildServiceRegistry( configuration.getProperties() ) ); + configuration.buildSessionFactory( ServiceRegistryBuilder.buildServiceRegistry( configuration.getProperties() ) ).close(); } } diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/duplicatedgenerator/DuplicateTest.java b/hibernate-core/src/test/java/org/hibernate/test/annotations/duplicatedgenerator/DuplicateTest.java index fff6b6db63..e8b198f525 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/duplicatedgenerator/DuplicateTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/annotations/duplicatedgenerator/DuplicateTest.java @@ -4,6 +4,7 @@ import org.junit.Assert; import org.junit.Test; import org.hibernate.AnnotationException; +import org.hibernate.SessionFactory; import org.hibernate.cfg.AnnotationConfiguration; import org.hibernate.cfg.Environment; import org.hibernate.service.ServiceRegistry; @@ -18,19 +19,23 @@ public class DuplicateTest { AnnotationConfiguration cfg = new AnnotationConfiguration(); cfg.setProperty( Environment.HBM2DDL_AUTO, "create-drop" ); ServiceRegistry serviceRegistry = null; + SessionFactory sf = null; try { cfg.addAnnotatedClass( Flight.class ); cfg.addAnnotatedClass( org.hibernate.test.annotations.Flight.class ); cfg.addResource( "org/hibernate/test/annotations/orm.xml" ); cfg.addResource( "org/hibernate/test/annotations/duplicatedgenerator/orm.xml" ); serviceRegistry = ServiceRegistryBuilder.buildServiceRegistry( cfg.getProperties() ); - cfg.buildSessionFactory( serviceRegistry ); + sf = cfg.buildSessionFactory( serviceRegistry ); Assert.fail( "Should not be able to map the same entity name twice" ); } catch (AnnotationException ae) { //success } finally { + if (sf != null){ + sf.close(); + } if ( serviceRegistry != null ) { ServiceRegistryBuilder.destroy( serviceRegistry ); } diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/embeddables/EmbeddableIntegratorTest.java b/hibernate-core/src/test/java/org/hibernate/test/annotations/embeddables/EmbeddableIntegratorTest.java index e593b1c52d..cd7ef29c80 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/embeddables/EmbeddableIntegratorTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/annotations/embeddables/EmbeddableIntegratorTest.java @@ -33,6 +33,7 @@ import org.junit.Test; import org.hibernate.Session; import org.hibernate.SessionFactory; import org.hibernate.boot.registry.BootstrapServiceRegistryBuilder; +import org.hibernate.boot.registry.StandardServiceRegistry; import org.hibernate.boot.registry.StandardServiceRegistryBuilder; import org.hibernate.boot.registry.internal.BootstrapServiceRegistryImpl; import org.hibernate.cfg.Configuration; @@ -76,11 +77,13 @@ public class EmbeddableIntegratorTest extends BaseUnitTestCase { assertEquals(new BigDecimal("100"), inv.getInvestments().get(0).getAmount().getAmount()); sess.close(); + sf.close(); + StandardServiceRegistryBuilder.destroy( reg ); } @Test public void testWithIntegrator() { - ServiceRegistry reg = new StandardServiceRegistryBuilder( + StandardServiceRegistry reg = new StandardServiceRegistryBuilder( new BootstrapServiceRegistryBuilder().with( new InvestorIntegrator() ).build() ).build(); @@ -102,6 +105,8 @@ public class EmbeddableIntegratorTest extends BaseUnitTestCase { assertEquals(new BigDecimal("100"), inv.getInvestments().get(0).getAmount().getAmount()); sess.close(); + sf.close(); + StandardServiceRegistryBuilder.destroy( reg ); } private Investor getInvestor() { diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/entity/BasicHibernateAnnotationsTest.java b/hibernate-core/src/test/java/org/hibernate/test/annotations/entity/BasicHibernateAnnotationsTest.java index 8f6770fa97..7b5c2ce866 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/entity/BasicHibernateAnnotationsTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/annotations/entity/BasicHibernateAnnotationsTest.java @@ -37,6 +37,7 @@ import org.hibernate.Hibernate; import org.hibernate.HibernateException; import org.hibernate.Query; import org.hibernate.Session; +import org.hibernate.SessionFactory; import org.hibernate.Transaction; import org.hibernate.cfg.Configuration; import org.hibernate.testing.DialectChecks; @@ -654,16 +655,21 @@ public class BasicHibernateAnnotationsTest extends BaseCoreFunctionalTestCase { @Test public void testTypeDefWithoutNameAndDefaultForTypeAttributes() { + SessionFactory sf=null; try { Configuration config = new Configuration(); config.addAnnotatedClass(LocalContactDetails.class); - config.buildSessionFactory( ServiceRegistryBuilder.buildServiceRegistry( config.getProperties() ) ); + sf = config.buildSessionFactory( ServiceRegistryBuilder.buildServiceRegistry( config.getProperties() ) ); fail("Did not throw expected exception"); } catch( AnnotationException ex ) { assertEquals( "Either name or defaultForType (or both) attribute should be set in TypeDefinition having typeClass org.hibernate.test.annotations.entity.PhoneNumberType", ex.getMessage()); + } finally { + if( sf != null){ + sf.close(); + } } } diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/fetchprofile/FetchProfileTest.java b/hibernate-core/src/test/java/org/hibernate/test/annotations/fetchprofile/FetchProfileTest.java index 2226f09406..e73b40ce03 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/fetchprofile/FetchProfileTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/annotations/fetchprofile/FetchProfileTest.java @@ -83,6 +83,7 @@ public class FetchProfileTest extends BaseUnitTestCase { "package info should not be parsed", sessionImpl.containsFetchProfileDefinition( "package-profile-1" ) ); + sessionImpl.close(); } @Test @@ -93,7 +94,7 @@ public class FetchProfileTest extends BaseUnitTestCase { config.addAnnotatedClass( Country.class ); try { - config.buildSessionFactory( serviceRegistry ); + config.buildMappings(); fail(); } catch ( MappingException e ) { @@ -109,7 +110,7 @@ public class FetchProfileTest extends BaseUnitTestCase { config.addAnnotatedClass( Country.class ); try { - config.buildSessionFactory( serviceRegistry ); + config.buildMappings(); fail(); } catch ( MappingException e ) { @@ -125,7 +126,7 @@ public class FetchProfileTest extends BaseUnitTestCase { config.addAnnotatedClass( Country.class ); try { - config.buildSessionFactory( serviceRegistry ); + config.buildMappings(); fail(); } catch ( MappingException e ) { @@ -151,6 +152,7 @@ public class FetchProfileTest extends BaseUnitTestCase { "fetch profile not parsed properly", sessionImpl.containsFetchProfileDefinition( "orders-profile" ) ); + sessionImpl.close(); // now the same with no xml config = new Configuration(); @@ -158,7 +160,7 @@ public class FetchProfileTest extends BaseUnitTestCase { config.addAnnotatedClass( Order.class ); config.addAnnotatedClass( Country.class ); try { - config.buildSessionFactory( serviceRegistry ); + config.buildMappings(); fail(); } catch ( MappingException e ) { @@ -186,5 +188,6 @@ public class FetchProfileTest extends BaseUnitTestCase { "fetch profile not parsed properly", sessionImpl.containsFetchProfileDefinition( "package-profile-2" ) ); + sessionImpl.close(); } } \ No newline at end of file diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/fkcircularity/FkCircularityTest.java b/hibernate-core/src/test/java/org/hibernate/test/annotations/fkcircularity/FkCircularityTest.java index daca31513f..f8829b2f24 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/fkcircularity/FkCircularityTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/annotations/fkcircularity/FkCircularityTest.java @@ -25,17 +25,7 @@ import org.hibernate.testing.ServiceRegistryBuilder; public class FkCircularityTest { private static final Logger log = Logger.getLogger( FkCircularityTest.class ); - private ServiceRegistry serviceRegistry; - @Before - public void setUp() { - serviceRegistry = ServiceRegistryBuilder.buildServiceRegistry( Environment.getProperties() ); - } - - @After - public void tearDown() { - if (serviceRegistry != null) ServiceRegistryBuilder.destroy(serviceRegistry); - } @Test public void testJoinedSublcassesInPK() { try { @@ -44,7 +34,7 @@ public class FkCircularityTest { config.addAnnotatedClass(B.class); config.addAnnotatedClass(C.class); config.addAnnotatedClass(D.class); - config.buildSessionFactory( serviceRegistry ); + config.buildMappings( ); String[] schema = config .generateSchemaCreationScript(new SQLServerDialect()); for (String s : schema) { @@ -66,7 +56,7 @@ public class FkCircularityTest { config.addAnnotatedClass(ClassB.class); config.addAnnotatedClass(ClassC.class); config.addAnnotatedClass(ClassD.class); - config.buildSessionFactory( serviceRegistry ); + config.buildMappings( ); String[] schema = config .generateSchemaCreationScript(new HSQLDialect()); for (String s : schema) { diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/id/JoinColumnOverrideTest.java b/hibernate-core/src/test/java/org/hibernate/test/annotations/id/JoinColumnOverrideTest.java index 440f63f802..af9bee9c05 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/id/JoinColumnOverrideTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/annotations/id/JoinColumnOverrideTest.java @@ -58,7 +58,7 @@ public class JoinColumnOverrideTest extends BaseUnitTestCase { config.addAnnotatedClass(Bunny.class); config.addAnnotatedClass(PointyTooth.class); config.addAnnotatedClass(TwinkleToes.class); - config.buildSessionFactory( ServiceRegistryBuilder.buildServiceRegistry( config.getProperties() ) ); + config.buildMappings( ); String[] schema = config .generateSchemaCreationScript(new SQLServerDialect()); for (String s : schema) { diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/id/sequences/JoinColumnOverrideTest.java b/hibernate-core/src/test/java/org/hibernate/test/annotations/id/sequences/JoinColumnOverrideTest.java index 1db1a9e9d4..8629c96082 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/id/sequences/JoinColumnOverrideTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/annotations/id/sequences/JoinColumnOverrideTest.java @@ -36,7 +36,7 @@ public class JoinColumnOverrideTest extends BaseUnitTestCase { config.addAnnotatedClass(Bunny.class); config.addAnnotatedClass(PointyTooth.class); config.addAnnotatedClass(TwinkleToes.class); - config.buildSessionFactory( ServiceRegistryBuilder.buildServiceRegistry( config.getProperties() ) ); + config.buildMappings( ); String[] schema = config.generateSchemaCreationScript( new SQLServerDialect() ); for (String s : schema) { log.debug(s); diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/immutable/ImmutableTest.java b/hibernate-core/src/test/java/org/hibernate/test/annotations/immutable/ImmutableTest.java index b91f6d84fa..d88158df63 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/immutable/ImmutableTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/annotations/immutable/ImmutableTest.java @@ -156,7 +156,7 @@ public class ImmutableTest extends BaseCoreFunctionalTestCase { try { Configuration config = new Configuration(); config.addAnnotatedClass(Foobar.class); - config.buildSessionFactory( ServiceRegistryBuilder.buildServiceRegistry( config.getProperties() ) ); + config.buildMappings( ); fail(); } catch (AnnotationException ae) { diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/namingstrategy/NamingStrategyTest.java b/hibernate-core/src/test/java/org/hibernate/test/annotations/namingstrategy/NamingStrategyTest.java index 836bc53183..3c2c45a2d3 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/namingstrategy/NamingStrategyTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/annotations/namingstrategy/NamingStrategyTest.java @@ -10,6 +10,7 @@ import org.junit.After; import org.junit.Before; import org.junit.Test; +import org.hibernate.SessionFactory; import org.hibernate.cfg.AnnotationConfiguration; import org.hibernate.cfg.EJB3NamingStrategy; import org.hibernate.cfg.Environment; @@ -48,7 +49,7 @@ public class NamingStrategyTest { config.setNamingStrategy(new DummyNamingStrategy()); config.addAnnotatedClass(Address.class); config.addAnnotatedClass(Person.class); - config.buildSessionFactory( serviceRegistry ); + config.buildMappings(); } catch( Exception e ) { StringWriter writer = new StringWriter(); @@ -59,12 +60,13 @@ public class NamingStrategyTest { } @Test public void testWithEJB3NamingStrategy() throws Exception { + SessionFactory sf = null; try { AnnotationConfiguration config = new AnnotationConfiguration(); config.setNamingStrategy(EJB3NamingStrategy.INSTANCE); config.addAnnotatedClass(A.class); config.addAnnotatedClass(AddressEntry.class); - config.buildSessionFactory( serviceRegistry ); + sf = config.buildSessionFactory( serviceRegistry ); Mappings mappings = config.createMappings(); boolean foundIt = false; @@ -84,6 +86,10 @@ public class NamingStrategyTest { e.printStackTrace(new PrintWriter(writer)); log.debug(writer.toString()); fail(e.getMessage()); + } finally { + if( sf != null ){ + sf.close(); + } } } @Test @@ -92,7 +98,7 @@ public class NamingStrategyTest { AnnotationConfiguration config = new AnnotationConfiguration(); config.addAnnotatedClass(Address.class); config.addAnnotatedClass(Person.class); - config.buildSessionFactory( serviceRegistry ); + config.buildMappings(); } catch( Exception e ) { StringWriter writer = new StringWriter(); diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/onetoone/OneToOneErrorTest.java b/hibernate-core/src/test/java/org/hibernate/test/annotations/onetoone/OneToOneErrorTest.java index 09959cc0a3..0ef63b9fca 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/onetoone/OneToOneErrorTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/annotations/onetoone/OneToOneErrorTest.java @@ -5,6 +5,7 @@ import org.junit.Assert; import org.junit.Test; import org.hibernate.AnnotationException; +import org.hibernate.SessionFactory; import org.hibernate.cfg.AnnotationConfiguration; import org.hibernate.cfg.Environment; import org.hibernate.service.ServiceRegistry; @@ -21,18 +22,23 @@ public class OneToOneErrorTest { .addAnnotatedClass( ShowDescription.class ); cfg.setProperty( Environment.HBM2DDL_AUTO, "create-drop" ); ServiceRegistry serviceRegistry = null; + SessionFactory sessionFactory = null; try { serviceRegistry = ServiceRegistryBuilder.buildServiceRegistry( Environment.getProperties() ); - cfg.buildSessionFactory( serviceRegistry ); + sessionFactory = cfg.buildSessionFactory( serviceRegistry ); Assert.fail( "Wrong mappedBy does not fail property" ); } catch (AnnotationException e) { //success } finally { + if(sessionFactory!=null){ + sessionFactory.close(); + } if ( serviceRegistry != null ) { ServiceRegistryBuilder.destroy( serviceRegistry ); } + } } } \ No newline at end of file diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/uniqueconstraint/UniqueConstraintValidationTest.java b/hibernate-core/src/test/java/org/hibernate/test/annotations/uniqueconstraint/UniqueConstraintValidationTest.java index 9dc3a91cf0..788c130427 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/uniqueconstraint/UniqueConstraintValidationTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/annotations/uniqueconstraint/UniqueConstraintValidationTest.java @@ -43,7 +43,8 @@ public class UniqueConstraintValidationTest extends BaseUnitTestCase { cfg.buildMappings(); ServiceRegistryImplementor serviceRegistry = (ServiceRegistryImplementor) new StandardServiceRegistryBuilder() .applySettings(cfg.getProperties()).build(); - cfg.buildSessionFactory(serviceRegistry); + cfg.buildSessionFactory(serviceRegistry).close(); + serviceRegistry.destroy(); } @Entity diff --git a/hibernate-core/src/test/java/org/hibernate/test/extendshbm/ExtendsTest.java b/hibernate-core/src/test/java/org/hibernate/test/extendshbm/ExtendsTest.java index 19bebca350..c51731f2e6 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/extendshbm/ExtendsTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/extendshbm/ExtendsTest.java @@ -59,8 +59,8 @@ public class ExtendsTest extends BaseUnitTestCase { cfg.addResource( getBaseForMappings() + "extendshbm/Person.hbm.xml" ); cfg.addResource( getBaseForMappings() + "extendshbm/Employee.hbm.xml" ); - cfg.buildSessionFactory( serviceRegistry ); - +// cfg.buildSessionFactory( serviceRegistry ); + cfg.buildMappings(); assertNotNull( cfg.getClassMapping( "org.hibernate.test.extendshbm.Customer" ) ); assertNotNull( cfg.getClassMapping( "org.hibernate.test.extendshbm.Person" ) ); assertNotNull( cfg.getClassMapping( "org.hibernate.test.extendshbm.Employee" ) ); @@ -117,8 +117,8 @@ public class ExtendsTest extends BaseUnitTestCase { ); cfg.addResource( getBaseForMappings() + "extendshbm/Employee.hbm.xml" ); - cfg.buildSessionFactory( serviceRegistry ); - +// cfg.buildSessionFactory( serviceRegistry ); + cfg.buildMappings(); fail( "Should not be able to build sessionFactory without a Person" ); } catch ( HibernateException e ) { @@ -134,8 +134,9 @@ public class ExtendsTest extends BaseUnitTestCase { try { cfg.addResource( getBaseForMappings() + "extendshbm/allseparateinone.hbm.xml" ); - cfg.buildSessionFactory( serviceRegistry ); +// cfg.buildSessionFactory( serviceRegistry ); + cfg.buildMappings(); assertNotNull( cfg.getClassMapping( "org.hibernate.test.extendshbm.Customer" ) ); assertNotNull( cfg.getClassMapping( "org.hibernate.test.extendshbm.Person" ) ); assertNotNull( cfg.getClassMapping( "org.hibernate.test.extendshbm.Employee" ) ); diff --git a/hibernate-core/src/test/java/org/hibernate/test/mapping/usertypes/UserTypeMappingTest.java b/hibernate-core/src/test/java/org/hibernate/test/mapping/usertypes/UserTypeMappingTest.java index 4b46548dc3..2f1216cfc3 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/mapping/usertypes/UserTypeMappingTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/mapping/usertypes/UserTypeMappingTest.java @@ -38,6 +38,12 @@ private ServiceRegistry serviceRegistry; cfg.setProperties(p); serviceRegistry = ServiceRegistryBuilder.buildServiceRegistry( cfg.getProperties() ); } + + public void tearDown(){ + if(serviceRegistry!=null){ + ServiceRegistryBuilder.destroy( serviceRegistry ); + } + } @Test public void testFirstTypeThenEntity(){ @@ -45,6 +51,7 @@ private ServiceRegistry serviceRegistry; .addResource("org/hibernate/test/mapping/usertypes/TestEntity.hbm.xml"); SessionFactory sessions=cfg.buildSessionFactory(serviceRegistry); Assert.assertNotNull(sessions); + sessions.close(); } @Test @@ -54,6 +61,7 @@ private ServiceRegistry serviceRegistry; SessionFactory sessions=cfg.buildSessionFactory(serviceRegistry); Assert.assertNotNull(sessions); + sessions.close(); } } diff --git a/hibernate-core/src/test/java/org/hibernate/test/multitenancy/ConfigurationValidationTest.java b/hibernate-core/src/test/java/org/hibernate/test/multitenancy/ConfigurationValidationTest.java index f05fde3e99..1218b395b3 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/multitenancy/ConfigurationValidationTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/multitenancy/ConfigurationValidationTest.java @@ -27,7 +27,8 @@ public class ConfigurationValidationTest extends BaseUnitTestCase { cfg.buildMappings(); ServiceRegistryImplementor serviceRegistry = (ServiceRegistryImplementor) new StandardServiceRegistryBuilder() .applySettings( cfg.getProperties() ).build(); - cfg.buildSessionFactory( serviceRegistry ); + cfg.buildSessionFactory( serviceRegistry ).close(); + serviceRegistry.destroy(); } @Test @@ -50,6 +51,7 @@ public class ConfigurationValidationTest extends BaseUnitTestCase { ) .build(); - cfg.buildSessionFactory( serviceRegistry ); + cfg.buildSessionFactory( serviceRegistry ).close(); + serviceRegistry.destroy(); } } diff --git a/hibernate-core/src/test/java/org/hibernate/test/transaction/jdbc/TestExpectedUsage.java b/hibernate-core/src/test/java/org/hibernate/test/transaction/jdbc/TestExpectedUsage.java index 57ea14b8a6..3979414c2e 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/transaction/jdbc/TestExpectedUsage.java +++ b/hibernate-core/src/test/java/org/hibernate/test/transaction/jdbc/TestExpectedUsage.java @@ -131,6 +131,7 @@ public class TestExpectedUsage extends BaseUnitTestCase { } finally { logicalConnection.close(); + transactionContext.getTransactionEnvironment().getSessionFactory().close(); } } diff --git a/hibernate-core/src/test/java/org/hibernate/test/transaction/jta/BasicDrivingTest.java b/hibernate-core/src/test/java/org/hibernate/test/transaction/jta/BasicDrivingTest.java index cff9ff6303..53704454ed 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/transaction/jta/BasicDrivingTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/transaction/jta/BasicDrivingTest.java @@ -153,6 +153,7 @@ public class BasicDrivingTest extends BaseUnitTestCase { } finally { logicalConnection.close(); + transactionContext.getTransactionEnvironment().getSessionFactory().close(); } } diff --git a/hibernate-core/src/test/java/org/hibernate/test/transaction/jta/ManagedDrivingTest.java b/hibernate-core/src/test/java/org/hibernate/test/transaction/jta/ManagedDrivingTest.java index 78724728ae..5aba6fbd39 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/transaction/jta/ManagedDrivingTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/transaction/jta/ManagedDrivingTest.java @@ -171,6 +171,7 @@ public class ManagedDrivingTest extends BaseUnitTestCase { } finally { logicalConnection.close(); + transactionContext.getTransactionEnvironment().getSessionFactory().close(); } } } diff --git a/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/metadata/MetadataTest.java b/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/metadata/MetadataTest.java index 6f23426606..62df7cd874 100644 --- a/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/metadata/MetadataTest.java +++ b/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/metadata/MetadataTest.java @@ -76,6 +76,7 @@ public class MetadataTest extends BaseEntityManagerFunctionalTestCase { cfg.buildMappings(); SessionFactoryImplementor sfi = (SessionFactoryImplementor) cfg.buildSessionFactory( serviceRegistry() ); MetamodelImpl.buildMetamodel( cfg.getClassMappings(), sfi, true ); + sfi.close(); } @Test