Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Load Hibernate configuration from a different file

Ainar Martin
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I need to read the Hibernate configuration properties from a file name different that hibernate.cfg.xml

Following code works but is deprecated:

SessionFactory sessionFactory=new Configuration().configure("hibernate.content.cfg.xml").buildSessionFactory();

But when I try to use the new configuration method:

serviceRegistry = new ServiceRegistryBuilder().applySettings(configuration.getProperties()).buildServiceRegistry();
sessionFactory = configuration.buildSessionFactory(serviceRegistry);

it doesn't work.

How should I get Hibernate to read a different configuration file?

Thank you.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic