You can do some thing like:
-Store the database details in secure store encrypted
-Read them from your Hibernate class that configures the SessionFactory
-Add those properties to Configuration object and configure your session factory.
Code:
//hibernateConfURL - myhibernate.cfg.xml
Configuration config= new Configuration();
config.configure(hibernateConfURL);
String user = "user"; //read it from secure store
String password = "password"; //read it from secure store
config.setProperty(Environment.USER, password);
config.setProperty(Environment.PASS, password);
SessionFactory sessionFactory = config.buildSessionFactory();
Here you can store user name and password encrypted in a file and read them from your program and decrypt them
Thanks