File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Object Relational Mapping and the fly likes Hibernate and Persistence.xml Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Hibernate and Persistence.xml" Watch "Hibernate and Persistence.xml" New topic
Author

Hibernate and Persistence.xml

Khaled Mahmoud
Ranch Hand

Joined: Jul 15, 2006
Posts: 361
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 ]

SCJP, SCJD,SCWCD,SCDJWS,SCEA 5 MCP-C#, MCP-ASP.NET - http://www.khaledinho.com/
Life is the biggest school
Pierre Henry
Ranch Hand

Joined: Oct 01, 2003
Posts: 31
Yes, all persistance provider must be configured.

For Hibernate, the persistance provider is in a file called 'hibernate.cfg.xml'


"A good method shouldn't bypass one screen long"<br />"genius is the knowledge left when one has forgotten everything"
Mike Keith
author
Ranch Hand

Joined: Jul 14, 2005
Posts: 304
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.


-Mike
Pro JPA 2: Mastering the Java Persistence API
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17250
    
    6

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


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
yusuf Kaplan
Ranch Hand

Joined: Mar 11, 2011
Posts: 58
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 ???
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Hibernate and Persistence.xml