Hibernate3 Study Notes (2) hibernate configuration file hibernate. cfg. xml

Source: Internet
Author: User

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:

  1. <? XML version = "1.0" encoding = "UTF-8"?>
  2. <! Doctype hibernate-Configuration
  3. Public "-// hibernate/hibernate configuration DTD // en"
  4. Http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd>
  5. <Hibernate-configuration>
  6. <Session-factory name = "CDMA">
  7. <! -- Local Connection Properties -->
  8. <Property name = "hibernate. Connection. url">
  9. JDBC: oracle: thin: @ 10.52.16.138: 1521: oragxlu
  10. </Property>
  11. <Property name = "hibernate. Connection. driver_class">
  12. Oracle. JDBC. Driver. oracledriver
  13. </Property>
  14. <Property name = "hibernate. Connection. username"> cdmagis </property>
  15. <Property name = "hibernate. Connection. Password"> cdmagis </property>
  16. <! -- Property name = "hibernate. Connection. pool_size"> </Property -->
  17. <! -- Dialect for Oracle (any version) -->
  18. <Property name = "dialect">
  19. Org. hibernate. dialect. oracledialect
  20. </Property>
  21. <Property name = "hibernate. show_ SQL"> true </property>
  22. <Property name = "hibernate. transaction. factory_class">
  23. Org. hibernate. transaction. jdbctransactionfactory
  24. </Property>
  25. <Mapping Resource = "cdmabts. HBM. xml"/>
  26. </Session-factory>
  27. </Hibernate-configuration>

The first part is the standard header information of the XML file. You only need to pay attention to the version information.

  1. <PropertyName = "hibernate. Connection. url">
  2. JDBC: oracle: thin: @ 10.52.16.138: 1521: oragxlu
  3. </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.

 

  1. <PropertyName = "hibernate. Connection. driver_class">
  2. Oracle. JDBC. Driver. oracledriver
  3. </Property>

This section describes the driver used to connect to the database.

 

  1. <PropertyName = "hibernate. Connection. username">Cdmagis</Property>
  2. <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.

  1. <PropertyName = "dialect">
  2. Org. hibernate. dialect. oracledialect
  3. </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.

  1. <PropertyName = "hibernate. transaction. factory_class">
  2. Org. hibernate. transaction. jdbctransactionfactory
  3. </Property>

Transaction Management configuration.

 

<MappingResource = "cdmabts. HBM. xml"/>

This configuration is important. To generate a table's persistence layer, you must configure mapping here.

 

 

 

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.