HHH-8127 OutOfMemoryError when running tests

This commit is contained in:
Strong Liu 2013-04-02 18:25:08 +08:00
parent b10f6c5d24
commit 3551bfa58f
25 changed files with 141 additions and 54 deletions

View File

@ -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"

View File

@ -120,6 +120,7 @@ public class TemplateTest extends BaseUnitTestCase {
public static void closeSessionFactory() {
if ( SESSION_FACTORY != null ) {
SESSION_FACTORY.close();
SESSION_FACTORY = null;
}
}

View File

@ -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 );
}

View File

@ -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 );
}

View File

@ -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();
}
}

View File

@ -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<String>();
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<String>();
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<String>();
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<String>();
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<Class<?>> classesUnderTest, List<String> configFiles) {

View File

@ -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();
}
}

View File

@ -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 );
}

View File

@ -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() {

View File

@ -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();
}
}
}

View File

@ -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();
}
}

View File

@ -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) {

View File

@ -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) {

View File

@ -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);

View File

@ -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) {

View File

@ -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();

View File

@ -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 );
}
}
}
}

View File

@ -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

View File

@ -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" ) );

View File

@ -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();
}
}

View File

@ -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();
}
}

View File

@ -131,6 +131,7 @@ public class TestExpectedUsage extends BaseUnitTestCase {
}
finally {
logicalConnection.close();
transactionContext.getTransactionEnvironment().getSessionFactory().close();
}
}

View File

@ -153,6 +153,7 @@ public class BasicDrivingTest extends BaseUnitTestCase {
}
finally {
logicalConnection.close();
transactionContext.getTransactionEnvironment().getSessionFactory().close();
}
}

View File

@ -171,6 +171,7 @@ public class ManagedDrivingTest extends BaseUnitTestCase {
}
finally {
logicalConnection.close();
transactionContext.getTransactionEnvironment().getSessionFactory().close();
}
}
}

View File

@ -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