Hibernate configuration on runtime

Try like this it is working fine

AnnotationConfiguration conf = new AnnotationConfiguration().configure("/dronehibernate.cfg.xml");

conf.setProperty("hibernate.connection.url","jdbc:mysql://localhost/PAT_DRONE_DB1");

SessionFactory sessionFactory = conf.buildSessionFactory();

Session session = sessionFactory.openSession();

List<NetworkType> channelList = session.createQuery("from NetworkType").list();

Try to call conf.configure(); here.
And properties may need to have hibernate prefix like "hibernate.connection.username"
Hope it helps.

Tags:

Java

Hibernate