A summary of the first chapter of hibernate knowledge points

Source: Internet
Author: User

in the 1.Hibernate mapping file:

<generator class="increment"/>

1) The value of class equals native or increment: The primary key in the table is automatically generated;

2) The value of class equals assigned: The primary key is added manually ;

2. When you call save , the primary key value is queried from the database, even if there is no transaction commit (primary key generation policy is generated from the database)

3. Caching

1) One of the important functions of caching is to avoid repeatedly reading the database.

2) all caches are placed in the session, which is also known as the Hibernate framework of the first level of ease .

4. Status

1) the state of an object is also known as the life cycle of an object.

2) Hibernate has only been divided into 3 stages:

I. temporary, instantaneous ()(transient)

Ii. Persistence ( Persistent )

Iii. free, managed, detached (), offline (detached)

5. There are several steps to using Hibernate for persistence:

1) write the Persistence class PO, which is composed of POJO and mapping culture

2) get the Configuration( in WEB development, because hibernate.cfg.xml is on the default path the new Cofiguration () with no parameters . Configure ()

3) get sessionfactory

4) get Session, open transaction

5) manipulate the database in an object-oriented manner

6) close the transaction and close the Session

How the 6.Hibernate works:

1) through configuration config = new configuration ()// Read and parse the Hibernate.cfg.xml config file

2) by the hibernate.cfg.xml

<mapping resourse="com/xxx/user.hbm.xml"/> Read and parse mapping information

3) via sessionfactory SF = Config.buildsessionfactoty ();// Create sessionfactory

4) Session session = Sf.opensession ();// Open session

5) Transaction tx = Session.begintransaction ();// Create and start transaction transation

6) Persistent operate operation data, persistent operation

7) Tx.commit ();// commit a transaction

8) Close Session

9) Close sessionfactory

7. Why Hibernate

1) The Code for JDBC access to the database is encapsulated, which greatly simplifies the tedious repetitive code of the data access layer .

2) Hibernate is a JDBC -based , mainstream persistence framework that is an excellent DRM implementation. He simplifies the coding of DAO to a great extent .

3) Hibernate uses the Java reflection mechanism rather than the bytecode enhancer to achieve transparency.

4) Hibernate performance is very good, because it is a lightweight framework, the flexibility of mapping is excellent, it supports a variety of relational databases, from one-to-many complex relationships.

8. Summary of Knowledge points :

1) additions and deletions must have a transaction, because hibernate sets the Connection object to non-self- commit mode

2) query can not be required (opensession Way)

3) How to hibernateutil

4) inside the Dao object is sessionfactory


1) Create session Object

2) It is thread-safe

3) generally one project, only one sessionfactory object

4) Sessionfactory will manage meta data


1) represents a session of the database

2) There must be a JDBC Connection object in the Session object. Connection is a one-to-many relationship, meaning that a Session can be associated with different (multiple) Connection, but Session when used, there is only one Connection .

I.opensession created a session, and there is already a Connection associated with the session .

II.session.disconnect (), at which time the session is not associated with any connection

III.session.reconnect this session will re-associate a connection

3) The Session is not thread-safe.

4) There are two ways to get the session:a) opensession,b) getcurrentsession

5) Every time you call opensession , you will create a new Session .


generally in the programming middle finger is the object pool,hibernate inside, the default is to use the pool to manage Connection

What to look for in the 12.Dao method:

The connection configuration file (hibernate.cfg.xml) of the databaseshould be noted in the following areas:

1) <property name= "Hbm2ddl.auto" >CREATE</PROPERTY>: When you have created a table , you can annotate it, and if you comment, Adding an execution will add another piece of data to the original table , and no , a new table will be created to overwrite the previous table. ,

2) <property name= "Show_sql" >true</property>

<property name= "Format_sql" ><property/>: If you configure these two lines of code, the data will be displayed in the background at run time (for example: Create table data, add data, etc.)

status transition diagram:

A summary of the first chapter of hibernate knowledge points

Related Article

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.