Skip to content

Commit

Permalink
Adjust how things go when session factory could not be created
Browse files Browse the repository at this point in the history
  • Loading branch information
GenieTim committed Feb 15, 2024
1 parent 3cd938b commit 9c428a1
Showing 1 changed file with 6 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ private static void createSessionFactory() {
try {
sessionFactory = configuration.buildSessionFactory();
} catch (JDBCConnectionException | ServiceException ex) {
log.error("Failed to login: " + ex.getMessage(), ex);
configuration = new Configuration().configure();
success = false;
sessionFactory = null;
Expand All @@ -169,6 +170,7 @@ private static void createSessionFactory() {
"Database connection failed.");
}
System.out.println("Initial SessionFactory creation failed." + ex);
return;
} catch (Throwable ex) {
// Make sure you log the exception, as it might be swallowed
System.out.println("Initial SessionFactory creation failed." + ex);
Expand All @@ -177,9 +179,9 @@ private static void createSessionFactory() {
}
try {
// Check database authentication by beginning a transaction.
Session session = sessionFactory.getCurrentSession();
session.beginTransaction();
session.close();
Session session = sessionFactory.getCurrentSession();
session.beginTransaction();
session.close();
// If an exception hasn't been thrown, dbuser/dbpassword has
// successfully authenticated against the database.
// Now try authenticating the individual user by the email
Expand Down Expand Up @@ -212,7 +214,7 @@ private static void createSessionFactory() {
if (loginDialog.getUsername() != null) {
log.debug("Login failed for " + loginDialog.getUsername());
}
sessionFactory.close();
sessionFactory.close();
sessionFactory = null;
configuration = new Configuration().configure();
try {
Expand Down

0 comments on commit 9c428a1

Please sign in to comment.