When I use old deprecated hibernate method for building session factory, it works fine:
SessionFactory sessionFactory = new Configuration()
.configure().buildSessionFactory();
When I replace this with new method, its gets compiled but at runtime get unknown entity exception, seems like the new method is not picking up mapping resource="xyz.hbm.xml" property:
Configuration configuration = new Configuration().configure();
ServiceRegistry serviceRegistry
= new StandardServiceRegistryBuilder()
.applySettings(configuration.getProperties()).build();
// builds a session factory from the service registry
SessionFactory sessionFactory = `configuration.buildSessionFactory(serviceRegistry);`
My question is, do I need to make some changes in the configuration or add some property in hibernate.cfg.xml file so that the property is read and loaded while using the new method for building session factory?
I tried with below as well:
Configuration configuration = new Configuration(); configuration.configure("hibernate.cfg.xml"); ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder() .applySettings(configuration.getProperties()).build(); SessionFactory sessionFactory = configuration .buildSessionFactory(serviceRegistry);