Thanks very much javamonkey79 and costis for responding to this question.
Yes - I can read the hibernate.properties/cfg.xml file - but I wanted to avoid the file reading workflow.
It appears that Session::connection()
api is deprecated now, but it still works.
We also can retrieve the same info in another way as listed below.
OPTION 1
Session session = sessionFactory.openSession();
String dbURL = session.connection().getMetaData().getURL().toString();
session.close();
OPTION 2
Settings settings = ((SessionFactoryImpl) sessionFactory).getSettings();
if (settings != null) {
Connection connection = settings.getConnectionProvider().getConnection();
String dbURL = connection.getMetaData().getURL();
connection.close();
}
For MySql, the return URL will be in form of:
jdbc:mysql://localhost:3306/edm?useUnicode=true