Hibernate Small Stage Summary

Source: Internet
Author: User

(a) Getting Started with hibernate

In layman's terms: Hibernate is used for object-oriented manipulation of the database, which is a lightweight encapsulation of JDBC. (Traditionally, JDBC accesses the database in the Java World.) )

1) Hibernate qualitative: Object Relational mapping framework. (The underlying is still JDBC)

2) structure diagram of Hibernate frame

      

Parsing: Java Application applications

Persistent Object Persistence objects

Hibernate (Configuration, Session Factory, Session, Transation, Query, Criteria) six main interfaces

JNDI: (Java naming and directory Interface) is the Java Naming and directory interface

JDBC: (Java Date Base Connectivity) database connection, which is a Java API for executing statements

JTA: (Java Transaction API) global transaction processing

3) What is ORM?

ORM is an Object relational mapping (English: Object Relation Mapping, abbreviated ORM, or O/RM, or O/R Mapping),

is a program technology that enables the conversion of data between different types of systems in an object-oriented programming language.

In effect, it actually creates a "virtual object database" that can be used in a programming language.

4) What is persistence?

Persistence is the process of translating program data between instantaneous and persistent states

      POJO (Plain ordinary Java object) simple, non -regular Java objects are purely traditional Java objects. Which means that in some object/relation mapping tools,

The Persisent object that maintains database table records is a pure Java object that conforms to the Java Bean Specification and does not add other properties and methods. My understanding is that

The most basic Java Bean, only attribute fields and setter and getter methods.  

Parsing one: a Pojo (Plain ordinary Java object) is persisted after the PO

Javabean=pojo

Po=pojo+xml Configuration
It is a dto (Data transefer Object) to pass and pass directly with it.
Directly used to correspond to the presentation layer is VO

Parsing two: A Java class whose object or instance is stored in a database table is called a persisted class in Hibernate

Po=javabean+xml Configuration

The Pojo name is used to emphasize that a given object is an ordinary Java object, not a special object, or an enterprise JavaBean (ORM Framework Implementation product).

5) The unique identifier of the persisted object is OID

Parsing: We all know that Java memory addresses differ from one class to another

The relational database distinguishes the same record with the primary key

Hibernate uses the OID to establish the correspondence between objects in memory and records in the database

01. What is an OID?

Parsing: An OID is a persisted class (Student) corresponding to a data table primary key property that uniquely distinguishes a persisted object.

02. Use the packing class as much as possible

Analysis: A student score of 0, can not distinguish is to take the exam to obtain 0 points, or no results.

If the wrapper class is used, the database is stored in NULL, proving that the student did not take the exam

Differences: Wrapper classes and basic data types for Java

Basic types of Java wrapper classes:

Integer, Long, short, Byte, Character, Double, Float, Boolean, BigInteger, Bigdecmail

Among them, BigInteger and BigDecimal have no corresponding basic types, which are mainly applied to high precision operation, BigInteger support arbitrary precision Integer, bigdecimal support arbitrary precision operation with decimal point.

The Java language provides eight basic types: (six numeric types (four integers, two floating-point types), a character type, and a Boolean type. )
Integer: Includes int,short,byte,long, initial value is 0
Floating-point type: float,double, initial value is 0.0
Character: char, the initial value is a space, that is, "", if the output, on the console is not see the effect.
Boolean: Boolean, initial value is False

6) Primary key health policy (basic)

        

* Increment

The primary key increment is done by hibernate,

Principle: SELECT Max (ID), insert time Max (ID) +1, complete primary key increment

Pros: Cross-database

Cons: Multithreading concurrent access Problems (the first thread executes successfully and the second thread is an error)

* Identity

The self-increment is done by the underlying database, requiring the database to support the self-increment primary key MySQL support, which Oracle does not support

* Sequence

The number column generated by the underlying database provides a sequence to complete the primary key self-increment, requiring that the database must support serial MySQL not supported, Oracle support

Create sequence myseq; Create a sequence

INSERT into customer values (myseq.nextval); Call sequence when inserting data, sequence +1

* Native

Using the database to support the self-increment strategy, MySQL uses identity, Oracle uses sequence

Strategy 1)---> Strategy 4) requires that the database primary key must be a number because only the number can be self-increasing

* UUID

32-bit unique string, primary key using varchar type

In real development, use the program to provide the UUID value

*assigned

Manually specify the value of the primary key, which generally has practical significance, such as order number (20160114-a002) 20160114-b001 20160114-c002.

7) Transitions between three states of Java objects in hibernate

        

        

8) Dirty check and caching mechanism

What is a dirty check : When a transaction commits,Hibernate pairs the PO ( persisted object ) in the session detects whether the state of the persisted object has changed and updates the changes to the database if a change occurs.

(Current data is different than the original data)

The common denominator of the flush () method and the Clear () method in session sessions is to go to the database

Flush () database synchronization does not clear the cached

Clear () clears the cached

 

Hibernate Small Stage Summary

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.