Hibernate introduction (i) Hibernate configuration, running process and pros and cons analysis

Source: Internet
Author: User

What is Hibernate?

Hibernate is a ormapping frame
Hibernate is an operational framework for manipulating databases

Why to use HIBERNATEJDBC's disadvantage

1, the code is quite cumbersome
2, moving from one database to another database, you have to change a lot of content, poor
3. See:

When making a request, it is possible to extract the data directly from memory, a process called a data cache
Although JDBC provides a pool of database connections, it does not provide a data cache
4. JDBC technology is for SQL statement operations, not object-oriented operations

Advantages of JDBC: The advantages and disadvantages of high efficiency hibernate:

Advantages:

      Hibdrnate的代码是比较简单的      Hibernate是面向对象的操作      Hibernate的移动植性很强      Hibernate的缓存是世界级的

Disadvantages:

    不能干预sql语句的生成(hibernate的sql语句是内部生成的,如果对sql语句的优化要求比较高就不适合用hibernate,因此也不适用于有千万级别表的数据量)    表之间的结构复杂的话也不适合用hibernate,一般只适合于中小企业开发软件  
Hibernate.cfg.xml configuration file parsing
<hibernate-configuration>    <session-factory>        <!--the user name to link to the database--        < property name="Connection.username">Root</Property >        <!--the password to link to the database--            < property name="Connection.password">Root</Property >        <!--The URL of the linked database--        < property name="Connection.url">Jdbc:mysql://localhost:3306/itcastsh08_hibernate</Property >        <!--dialect tell hibernate what database to use--        < property name="dialect">Org.hibernate.dialect.MySQLDialect</Property >     <!--validate default values check the structure of tables based on persisted classes and mapping files The update Hibernate container, when started, is based on the The structure of the long class and mapping file checklist is created if it does not exist, and if present, updates the create every time the Hibernate container is started, regardless of whether the table exists, create-d ROP When you start the Hibernate container, the table is created and when the Hibernate container is destroyed, the table is deleted- -        < property name="Hbm2ddl.auto">Update</Property >Introducing a mapping file<mapping Resource="Cn/itcast/sh08/hibernate/domain/person.hbm.xml"/>     </session-factory></hibernate-configuration>

Other configurations:

Show_sql represents the output of SQL statements in the console
Format_sql represents the formatted output statement
The dialects are as follows:

All the dialects supported by hibernate

Imported JAR parsing


Antlr.jar uses it to implement HQL-to-SQL conversions
Util tool Set
C3P0 Database Connection Pool
DOM4J-DOM4J Parser
Hibernate3-hibernate's core package
Javassist Code generation Tool
jta-Transaction Processing Interface
log4j-Log System

Hibernate's execution process


Text parsing: Hibernate container The name attribute of the-hibernate.cfg.xml-*.hbm.xml-class element is added to the persisted class
Examples of specific illustrations:

2, about Sessionfactory

    1、sessionFactory是存放配置文件、映射文件、持久化类的信息的    2、sessionFactory只有一个    3、一个sessionFactory代表一个数据库的链接    4、sessionFactory类本身是线程安全的

3. About session

        1、一个session代表数据库的一个链接        2、Crud操作是通过session来完成的

4, transaction is created by the session, because there are links, after the transaction
5, after the completion of the operation, the transaction must be submitted, the session must be closed

Hibernate Introduction (i) Hibernate configuration, running process, and advantages and disadvantages of the analysis

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.