diff --git a/spring-exceptions/src/main/resources/hibernate-mysql.properties b/spring-exceptions/src/main/resources/hibernate-mysql.properties index 5e8c7be141..49ca7fb3d1 100644 --- a/spring-exceptions/src/main/resources/hibernate-mysql.properties +++ b/spring-exceptions/src/main/resources/hibernate-mysql.properties @@ -2,7 +2,6 @@ hibernate.connection.username=tutorialuser hibernate.connection.password=tutorialmy5ql hibernate.connection.driver_class=com.mysql.jdbc.Driver hibernate.dialect=org.hibernate.dialect.MySQL5Dialect -#hibernate.connection.datasource=jdbc:mysql://localhost:3306/spring_hibernate4_exceptions?createDatabaseIfNotExist=true hibernate.connection.url=jdbc:mysql://localhost:3306/spring_hibernate4_exceptions?createDatabaseIfNotExist=true hibernate.show_sql=false -hibernate.hbm2ddl.auto=create +hibernate.hbm2ddl.auto=create \ No newline at end of file diff --git a/spring-exceptions/src/test/java/org/baeldung/ex/mappingexception/Cause4MappingExceptionIntegrationTest.java b/spring-exceptions/src/test/java/org/baeldung/ex/mappingexception/Cause4MappingExceptionIntegrationTest.java index 37e624b16c..ea24a1342e 100644 --- a/spring-exceptions/src/test/java/org/baeldung/ex/mappingexception/Cause4MappingExceptionIntegrationTest.java +++ b/spring-exceptions/src/test/java/org/baeldung/ex/mappingexception/Cause4MappingExceptionIntegrationTest.java @@ -18,8 +18,16 @@ public class Cause4MappingExceptionIntegrationTest { @Test public final void givenEntityIsPersisted_thenException() throws IOException { - final Configuration configuration = new Configuration(); + final SessionFactory sessionFactory = configureSessionFactory(); + final Session session = sessionFactory.openSession(); + session.beginTransaction(); + session.saveOrUpdate(new Foo()); + session.getTransaction().commit(); + } + + private final SessionFactory configureSessionFactory() throws IOException { + final Configuration configuration = new Configuration(); final InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream("hibernate-mysql.properties"); final Properties hibernateProperties = new Properties(); hibernateProperties.load(inputStream); @@ -29,11 +37,7 @@ public class Cause4MappingExceptionIntegrationTest { final ServiceRegistry serviceRegistry = new ServiceRegistryBuilder().applySettings(configuration.getProperties()).buildServiceRegistry(); final SessionFactory sessionFactory = configuration.buildSessionFactory(serviceRegistry); - - final Session session = sessionFactory.openSession(); - session.beginTransaction(); - session.saveOrUpdate(new Foo()); - session.getTransaction().commit(); + return sessionFactory; } }