From b9d4261948c98a7a19dd56497c7c518faef82a5f Mon Sep 17 00:00:00 2001 From: Tim Bernhard Date: Tue, 12 Nov 2019 14:55:32 +0100 Subject: [PATCH] Use HibernateUtil instead of Factory to get hibernate properties for database migration --- .../mcz/imagecapture/data/AllowedVersionLifeCycle.java | 9 +++++++-- .../edu/harvard/mcz/imagecapture/data/HibernateUtil.java | 4 ++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/main/java/edu/harvard/mcz/imagecapture/data/AllowedVersionLifeCycle.java b/src/main/java/edu/harvard/mcz/imagecapture/data/AllowedVersionLifeCycle.java index bfbf41c9..7bc91a27 100644 --- a/src/main/java/edu/harvard/mcz/imagecapture/data/AllowedVersionLifeCycle.java +++ b/src/main/java/edu/harvard/mcz/imagecapture/data/AllowedVersionLifeCycle.java @@ -31,6 +31,7 @@ import java.util.Iterator; import java.util.List; import java.util.Map; +import java.util.Properties; /** * @@ -94,12 +95,16 @@ public static String listAllowedVersions() { */ public static void upgrade() { // Load the Configuration from hibernate.cfg.xml - SessionFactoryImpl sessionFactory = + /*SessionFactoryImpl sessionFactory = (SessionFactoryImpl) HibernateUtil.getSessionFactory(); Map properties = sessionFactory.getProperties(); String url = (String) properties.get("connection.url"); String username = (String) properties.get("connection.username"); - String password = (String) properties.get("connection.password"); + String password = (String) properties.get("connection.password");*/ + Properties properties = HibernateUtil.getProperties(); + String url = properties.getProperty("hibernate.connection.url"); + String username = properties.getProperty("hibernate.connection.username"); + String password = properties.getProperty("hibernate.connection.username"); // Create the Flyway instance and point it to the database Flyway flyway = Flyway.configure().dataSource(url, username, password).load(); diff --git a/src/main/java/edu/harvard/mcz/imagecapture/data/HibernateUtil.java b/src/main/java/edu/harvard/mcz/imagecapture/data/HibernateUtil.java index e13a0d63..7a514638 100644 --- a/src/main/java/edu/harvard/mcz/imagecapture/data/HibernateUtil.java +++ b/src/main/java/edu/harvard/mcz/imagecapture/data/HibernateUtil.java @@ -54,6 +54,10 @@ public static void restartSessionFactory() { sessionFactory = configuration.buildSessionFactory(); } + public static Properties getProperties() { + return HibernateUtil.properties; + } + /** * Using the Hibernate configuration in Configuration from hibernate.cfg.xml