Two configuration file formats for hibernate

Source: Internet
Author: User
Tags config resource root directory

Hibernate has two types of configuration file formats, one is XML, Default is Hibernate.cfg.xml, one is properties, the default is hibernate.properties different configuration file, Hibernate has two configuration file format, one is XML, default is Hibernate.cfg.xml, one is Prope Rties, default is Hibernate.properties

Different configuration files, the initialization method for hibernate is not the same

For example, if you use a properties file as a configuration file

So the initialized code is roughly

Configuration config = new Configuration ();

Config.addclass (Myclass.class);

If the configuration file is XML, the

Configuration config = new Configuration (). config ();

The configuration file in the XML file format does not support the AddClass method!!! This is because the mpaaing file is already defined in the configuration file XML file, so there is no need to import the Pojo file in the encoding mode.

Another: A lot of articles on the Internet, and even some books have said that the Hibenate configuration file must be placed in the class root directory, reference to the API, found that this statement is not correct, such as configuration config = new Configuration (). config (configuration file name); it's perfectly OK.

All config methods are as follows:

  1 addcacheablefile (file xmlFile) If a cached XmlFile + ". Bin" exists and is newer than the ". Bin" File would be

Read directly.

2 Configuration addclass (Class persistentclass) Read A mapping from application resource, using a convention. 

3 Configuration adddirectory (File dir) Read all mapping the documents from directory tree. 4 Configuration adddocument (org.w3c.dom.Document doc) Read mappings from a DOM Document 5 Configuration addfile (File XM Lfile) Read mappings from a particular XML file 6 Configuration addfile (String xmlFile) read mappings from a Particula R XML file 7 void addfilterdefinition (filterdefinition definition) 8 Configuration addinputstream (InputStream xmlinputs Tream) Read mappings from the InputStream 9 Configuration Addjar (File jar) Read all mappings from a jar File confi 
Guration Addproperties (Properties extraproperties) Set The given properties one Configuration AddResource (String path) Read mappings from a application resource TRying different classloaders. Configuration AddResource (String path, ClassLoader ClassLoader) Read mappings from a application resource Ration addurl (URL url) read mappings from a URL-Configuration addxml (string xml) Read mappings from a string

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.