Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hibernate.cfg.xml vs Persistence.xml

What is the difference between Hibernate.cfg.xml and Persistence.xml

like image 269
Teshan Avatar asked Jun 13 '18 06:06

Teshan


People also ask

What is persistence xml Hibernate?

xml File. This file is used to override the default Hibernate settings and to add support for database types that are not out of the box (OOB database types are Oracle Server, Microsoft SQL Server, and MySQL).

Is it necessary to use Hibernate CFG xml for configuration in Hibernate?

Hibernate also requires a set of configuration settings related to database and other related parameters. All such information is usually supplied as a standard Java properties file called hibernate. properties, or as an XML file named hibernate. cfg.

What is Hibernate CFG xml?

Hibernate Configuration File(cfg file) is the file loaded into an hibernate application when working with hibernate. Hibernate uses this file to establish connection to the database server.It is an XML file which is used to define below information. Standard name for this file is hibernate.

What is persistent xml?

The persistence. xml file is a standard configuration file in JPA. It has to be included in the META-INF directory inside the JAR file that contains the entity beans.


1 Answers

If you are using Hibernate's proprietary API, you'll need the hibernate.cfg.xml. If you are using JPA i.e. Hibernate EntityManager, you will need the persistence.xml.

However, if you were using Hibernate Proprietary API and already have a hibernate.cfg.xml (and hbm.xml XML mapping files) but want to start using JPA, you can reuse the existing configuration files by referencing the hibernate.cfg.xml in the persistence.xml in the hibernate.ejb.cfgfile property - and thus have both files. Reusing existing hbm.xml files is IMO a realistic scenario that could justify keeping both (even if I'd probably migrate to JPA annotations on the long run).

like image 82
Ravi Jangid Avatar answered Sep 22 '22 07:09

Ravi Jangid