persistence workg

This commit is contained in:
eugenp 2013-08-13 13:34:58 +03:00
parent ec9b16694e
commit 2c1e9789a0
2 changed files with 11 additions and 8 deletions

View File

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

View File

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