Hibernate configuration file and mapping file

Source: Internet
Author: User

Hibernate is an open-source framework for a thorough ORM (objectrelational Mapping, objects Relational mapping ).

Let's take a look at the top-level view of the Hibernate architecture given by the official documentation:

Where the po=pojo+ mapping file

Depending on the architecture view, you can see that the entire project implemented with the Hibernate framework includes the entire important configuration file:

< Span style= "line-height:18px" >hibernate Profile: Implements Hibernate basic configuration, is hibernate is able to interact with the DB friendly base;

< Span style= "line-height:18px" >                            development Time Placement src directory, named: Hibernate.cfg.xml ( hibernate.properties )

Hibernate mapping File: Implements the mapping configuration of Pojo and DB tables;

In order to maintain the convenience is generally placed and the corresponding Pojo in the same directory, named pojoname. Hbm.xml. Although you can configure multiple Pojo mappings to a database table in a mapping file, it is recommended that you only configure one Pojo mapping with the database tables in a mapping file.

First,hibernate configuration file detailed

Hibernate configuration files are available in two forms: XML and properties

The personal suggestion uses XML, because the properties can not configure the associated mapping file, in the subsequent implementation will bring some unnecessary coding;

XML (hibernate.cfg.xml) file is detailed:

<?xml version= "1.0" encoding= "GBK"?><!--specify DTD information for hibernate configuration files--><! DOCTYPE hibernate-configuration Public "-//hibernate/hibernate configuration DTD 3.0//en" "http://www.hibernate.org/ Dtd/hibernate-configuration-3.0.dtd "><!--hibernate-configuration is the root element of the connection configuration file-->< hibernate-configuration><session-factory><!--Specifies the driver--><property name= "Connection.driver" used to connect to the database. _class ">com.mysql.jdbc.Driver</property><!--Specifies the database name of the Url,hibernate connection connecting to the database--><property name=" Connection.url ">jdbc:mysql://localhost/database name </property><!--Specify the user name to connect to the database--><property name=" Connection.username ">root</property><!--Specify the password to connect to the database--><property name=" Connection.password "> 32147</property><!--Specify the maximum number of connections in the connection pool--><property name= "Hibernate.c3p0.max_size" >20</property ><!--Specify the minimum number of connections in the connection pool--><property name= "Hibernate.c3p0.min_size" >1</property><!-- Specifies the timeout length for connections in the connection pool--><property name= "hibernate.c3P0.timeout ">5000</property><!--Specify the maximum number of statement objects in the connection pool--><property name=" Hibernate.c3p0.max_ Statements ">100</property><property name=" Hibernate.c3p0.idle_test_period ">3000</property> <property name= "hibernate.c3p0.acquire_increment" >2</property><property name= " Hibernate.c3p0.validate ">true</property><!--Specify Database dialect--><property name=" dialect "> org.hibernate.dialect.mysqlinnodbdialect</property><!--automatically create data tables--><property name= "as needed Hbm2ddl.auto ">update</property><!--shows the SQL--><property generated by hibernate persistence name=" Show_sql "> true</property><!--to format the SQL script before outputting--><property name= "Hibernate.format_sql" >true</property ><!--List all mapping files--><mapping resource= "Map file path/news.hbm.xml"/></session-factory></ Hibernate-configuration>

Properties (hibernate.properties) file detailed

# # mysql# dialect hibernate.dialect org.hibernate.dialect.MySQLDialecthibernate.dialect Org.hibernate.dialect.MySQLInnoDBDialecthibernate.dialect org.hibernate.dialect.mysqlmyisamdialect# Drive Hibernate.connection.driver_class com.mysql.jdbc.driver# database address Hibernate.connection.url JDBC:MYSQL://127.0.0.1/ datdabsename# User name Hibernate.connection.username root# password Hibernate.connection.password 12345# Whether to output the SQL statement in the console Hibernate.show_sql true/false# set whether the database table is automatically established based on the mapping file when Sessionfactory is created. Create-drop: Indicates that the database table that was just built will be drop when Sessionfactory is closed. This property can be Update/create-drop/createhibernate.hbm2ddl.auto update/create-drop/create############################## C3P0 Connection pool c3p0 connection pool ############################## #连接池最大链接数hibernate. c3p0.max_size Connection pool minimum number of connections hibernate.c3p0.min_size the timeout period for connection pooling Hibernate.c3p0.timeout 5000# cache statements Hibernate.c3p0.max_ Statements 100hibernate.c3p0.idle_test_period 3000hibernate.c3p0.acquire_increment 2hibernate.c3p0.validate true/ false############### JNDI (Java naming directory interface) Java named directory Interface ## # # # # # #当无需hibernate自己管理数据源而是直接访问容器管理数据源 use jndi############ #指定数据源JNDI名字hibernate. Connection.datasource dddd# File system Hibernate.jndi.class com.sun.jndi.fscontext.RefFSContextFactoryhibernate.jndi.url file:/#网络 # Specify JND The Initialcontextfactory implementation class, which is also optional. You do not need to specify this property if Jndi persists with hibernate access code in the same app Hibernate.jndi.class com.ibm.websphere.naming.wsninitialcontextfactory# Specifies the URL of the Jndi provider, which is optional if Jndi is in the same app as the hibernate-persisted code, you do not need to specify the attribute Hibernate.jndi.url iiop://localhost:900/# Specify the link database user name Hibernate.connection.username root# Specify the password Hibernate.connection.password 1111# specify the dialect hibernate.dialect org.hibernate.dialect.mysqldialect########################## Transaction API Transaction Property Description ########################### Specifies whether session hibernate.transaction.auto_close_session is automatically closed after the end of the transaction true/false# Specifies whether the session automatically flushes data to the underlying database after the transaction is complete hibernate.transaction.flush_before_completion true/false## specifies the type of all transaction factories for Hibernate, The attribute must be a direct or indirect subclass of Transactionfactory Hibernate.transaction.factory_class Org.hibernate.transaction.JTATransactionFactoryhibernate.transaction.factOry_class org.hibernate.transaction.jdbctransactionfactory## The property value is a jndi name, Hibernate will use Jtattransactionfactory to remove Jtaysertransactionjta.usertransaction Jta/usertransactionjta from the application server. UserTransaction javax.transaction.UserTransactionjta.UserTransaction usertransaction## The property value is a Transactionmanagerlookup class name, which is required when using a JVM-level cache, or when using the Hilo Generator policy in a JTA environment hibernate.transaction.manager_lookup_ Class Org.hibernate.transaction.JBossTransactionManagerLookuphibernate.transaction.manager_lookup_class Org.hibernate.transaction.WeblogicTransactionManagerLookuphibernate.transaction.manager_lookup_class Org.hibernate.transaction.WebSphereTransactionManagerLookuphibernate.transaction.manager_lookup_class Org.hibernate.transaction.OrionTransactionManagerLookuphibernate.transaction.manager_lookup_class Org.hibernate.transaction.ResinTransactionManagerLookup

Second, the mapping document detailed

Due to space, here the values are explained in detail for the most basic configuration

<?xml version= "1.0"? ><! DOCTYPE hibernate-mapping Public "-//hibernate/hibernate mapping DTD 3.0//en" "http://www.hibernate.org/dtd/ Hibernate-mapping-3.0.dtd "><!--


Hibernate configuration file and mapping file

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.