Hibernate from Getting started to mastering (iii) Hibernate configuration files

Source: Internet
Author: User
Tags connect

In the last blog post hibernate from Getting started to proficient (ii) Hibernate example Demo we have a simple understanding of the basic use of hibernate through an example demo, here we briefly review the hibernate framework of the use of steps.

Steps to use the Hibernate framework:

1, create the Hibernate configuration file

2, create a persistent class, that is, its instance needs to be saved to the database class

3. Create object-Relationship mapping file

4, through the Hibernate API to write access to the database code

Hibernate configuration file

This blog, we will focus on the hibernate profile. The hibernate configuration file has two main formats: one is the Java property file, the *.properties, which basically defines the parameters that are required to connect to various databases, and a file in XML format, In addition to defining the parameters required to connect to various databases, such a document can also define the mapping files used in the program. So in general, use XML-formatted configuration documents.
Configuration file in Properties form

The default file name for the configuration file in properties form is hibernate.properties, and a configuration file in the form of properties is as follows:

#指定

the driver class used by the database  
Hibernate.connection.driver_class = com.mysql.jdbc.Driver  
#指定数据库连接串  
Hibernate.connection.url = Jdbc:mysql://localhost:3306/hibernate_first  
#指定数据库连接的用户名  
Hibernate.connection.username = user  
#指定数据库连接的密码  
hibernate.connection.password = password  
#指定数据库使用的方言  
hibernate.dialect = org.hibernate.dialect.MySQLDialect  
#指定是否打印SQL语句  
hibernate.show_sql=true

XML-formatted configuration file

The default file name for a configuration file in XML format is Hibernate.cfg.xml, and an example of an XML configuration file is shown below:

<?xml version= ' 1.0 ' encoding= ' UTF-8 '? > <! DOCTYPE hibernate-configuration Public "-//hibernate/hibernate configuration DTD 3.0//en" "http://hibernate.so Urceforge.net/hibernate-configuration-3.0.dtd "> 

Configuration files in properties form and XML-formatted profiles can be used at the same time. When two types of configuration files are used concurrently, the settings in the XML configuration file overwrite the same properties of the properties configuration file.

This post we first introduced here, the next time we talk about the mapping file in hibernate, involving more content, we divided several times, thank you for your attention!

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.