11

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

Teshan
  • 351
  • 7
  • 10
  • 1
    Possible duplicate of [what is the purpose of two config files for Hibernate?](https://stackoverflow.com/questions/3807503/what-is-the-purpose-of-two-config-files-for-hibernate) – Alien Jun 13 '18 at 07:14

1 Answers1

4

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).

Ravi Jangid
  • 291
  • 1
  • 4
  • 15
  • 2
    Copied from https://stackoverflow.com/a/3808406/6572971 answer.Please go through this link https://meta.stackexchange.com/questions/78658/is-it-okay-to-copy-paste-answers-from-other-questions – Alien Jun 13 '18 at 07:21