Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Hibernate and Persistence.xml

 
Khaled Mahmoud
Ranch Hand
Posts: 361
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I read when using a persistence provider a configuration file called

Persistence.xml is used to configure the persistence provider. Is the persistence.xml file a standard file used to configure all persistence providers ??

The tutorial I read on the Hibernate website uses configuration files specific to hibernate and does not use the persistence.xml.

My question is : Does every persistence provider have its own set of configuration files and why the persistence.xml is not used in the case of hubernate.
[ July 15, 2007: Message edited by: Khaled Mahmoud ]
 
Pierre Henry
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, all persistance provider must be configured.

For Hibernate, the persistance provider is in a file called 'hibernate.cfg.xml'
 
Mike Keith
author
Ranch Hand
Posts: 304
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Khaled,

The persistence.xml file is the standard file that must be recognized and read by all providers. Most providers allow many of their implementation-specific properties to be specified in this file. The properties will only be recognized by the provider to which they apply and will be ignored by any other providers so it is reasonably portable.

Sometimes providers do not offer persistence properties for their extra features. In this case you have no choice but to use their own specific file or configuration mechanism. Check with the Hibernate doc to see if you really need to have the hibernate file for the feature that you want to enable as it is obviously not a portable way of configuring things to use proprietary files and you should avoid them when possible.
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The hibernate.cfg.xml is if you are not using JPA with Hibernate, if you are, then you will use the persistence.xml file instead of the hibernate.cfg.xml. Of course, this is all for Hibernate version 3.x anyone using a version before will only use the hibernate.cfg.xml.

Mark
 
yusuf Kaplan
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mark Spritzler wrote:The hibernate.cfg.xml is if you are not using JPA with Hibernate, if you are, then you will use the persistence.xml file instead of the hibernate.cfg.xml. Of course, this is all for Hibernate version 3.x anyone using a version before will only use the hibernate.cfg.xml.

Mark


So is it true, when you decide to use persistence.xml, then you can remove hibernate.cfg.xml ???
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic