For hibernate, hibernate. cfg. XML is a very important file. It uses XML format to save some very important parameters, such as database connection information and connection pool:
The following is an example of hibernate. cfg. XML in a project:
- <? XML version = "1.0" encoding = "UTF-8"?>
- <! Doctype hibernate-Configuration
- Public "-// hibernate/hibernate configuration DTD // en"
- Http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd>
- <Hibernate-configuration>
- <Session-factory name = "CDMA">
- <! -- Local Connection Properties -->
- <Property name = "hibernate. Connection. url">
- JDBC: oracle: thin: @ 10.52.16.138: 1521: oragxlu
- </Property>
- <Property name = "hibernate. Connection. driver_class">
- Oracle. JDBC. Driver. oracledriver
- </Property>
- <Property name = "hibernate. Connection. username"> cdmagis </property>
- <Property name = "hibernate. Connection. Password"> cdmagis </property>
- <! -- Property name = "hibernate. Connection. pool_size"> </Property -->
- <! -- Dialect for Oracle (any version) -->
- <Property name = "dialect">
- Org. hibernate. dialect. oracledialect
- </Property>
- <Property name = "hibernate. show_ SQL"> true </property>
- <Property name = "hibernate. transaction. factory_class">
- Org. hibernate. transaction. jdbctransactionfactory
- </Property>
- <Mapping Resource = "cdmabts. HBM. xml"/>
- </Session-factory>
- </Hibernate-configuration>
The first part is the standard header information of the XML file. You only need to pay attention to the version information.
- <PropertyName = "hibernate. Connection. url">
- JDBC: oracle: thin: @ 10.52.16.138: 1521: oragxlu
- </Property>
AttributeHibernate. Connection. url is used to record database connection information, connection methods, and other information. For example, the JDBC connection method is shown above. The target database is
Oracle uses thin connection, followed by db ip information and DB Sid.
- <PropertyName = "hibernate. Connection. driver_class">
- Oracle. JDBC. Driver. oracledriver
- </Property>
This section describes the driver used to connect to the database.
- <PropertyName = "hibernate. Connection. username">Cdmagis</Property>
- <PropertyName = "hibernate. Connection. Password">Cdmagis</Property>
The two parts are the DB user name and password.
<! -- Property name = "hibernate. Connection. pool_size"> </Property -->
This part is the configuration record of the connection pool. In this example, the connection pool is not used, so it is commented out. To use the connection pool, you only need to specify the size of the connection pool in the attribute.
- <PropertyName = "dialect">
- Org. hibernate. dialect. oracledialect
- </Property>
SQL dialect. The specific usage is not clear yet.
<PropertyName = "hibernate. show_ SQL">True</Property>
Specifies whether to output SQL statements when logs are output. If you want to study the internal implementation of hibernate, this function is very useful, because all database operations are actually the execution process of SQL.
- <PropertyName = "hibernate. transaction. factory_class">
- Org. hibernate. transaction. jdbctransactionfactory
- </Property>
Transaction Management configuration.
<MappingResource = "cdmabts. HBM. xml"/>
This configuration is important. To generate a table's persistence layer, you must configure mapping here.