Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use hibernate.properties file instead of hibernate.cfg.xml

I am trying to connect to DB in a servlet using Hibernate.I have read that we can use either hibernate.cfg.xml or hibernate.properties file for configuration of session.For me it worked with xml. Now when I am trying to use properties instead of xml its not working. It is saying that hibernate.cfg.xml not found.But nowhere I mentioned to use xml file and infact I have deleted that xml file.

Please Help me. And Please correct me if I am doing anything wrong.

like image 372
Salman Ahmad Avatar asked May 28 '14 10:05

Salman Ahmad


People also ask

Can we have hibernate properties instead of hibernate cfg XML?

An alternative approach to configuration is to specify a full configuration in a file named hibernate. cfg. xml . This file can be used as a replacement for the hibernate.

Is it necessary to use hibernate cfg XML for configuration in hibernate?

it's not mandatory to use hibernate. cfg. xml.

What will happen if both hibernate cfg XML and hibernate properties files are present in the classpath?

If both hibernate. properties and hibernate. cfg. xml files are present in the classpath then hibernate.


1 Answers

This code will call hibernate.cfg.xml by default:

Configuration configuration = new Configuration().configure();

And this code will call hibernate.properties by default:

Configuration configuration = new Configuration();

Hope it helps.

like image 50
proS Avatar answered Sep 28 '22 00:09

proS