Hibernate is based on principle. The main contents include:

A,

Second,

Three,

Four,

Fifth, business management

Vi.

Entity creation rules in Hibernate

Entity classes in Hibernate need to be mapped to tables in the database, so you need to pay attention to some rules when creating an entity class. If your entity class does not conform to these rules, the mapping may not work.

1)

Persistent classes provide a no-argument constructor

Generally, if no parameter constructor is created, the default is fine.

2)

Member variables are private and provided in common

3)

Properties of persistent classes should apply to encapsulated data types wherever possible.

The data type is

4)

Persistent classes need to be provided

5) Class cannot be modified with final.

This is due to

Hibernate Primary key Generation Strategy (7 types)

A primary key is the only field or combination of fields that exists to represent the uniqueness of the data. It’s as unique as your ID card. It says in the rule above

1) Identity (SQL use) : primary key increment. Primary key values are maintained by the MySQL database. You do not need to specify a primary key when typing.

2) Sequence (used by Oracle) : primary key generation strategy in Oracle databases.

3) increment: primary key increment It is maintained by Hibernate. The maximum number of ids in the table is queried before each insertion. +1 as the new primary key value. (There are concurrency issues)

4) HILO (Understanding) : high-low algorithm. The primary key increases automatically. It is maintained by Hibernate. Not used during development.

5) Native (recommended) : Hilo + Sequence +identity, automatic one of the three strategy.

6) UUID: generate random string as primary key. The primary key type must be String.

7) Assigned: natural primary key generation policy. Hibernate does not manage primary key values; they are entered by the developer, and an exception will occur if you forget to enter them manually.

Hibernate objects have three states

in

1. Each state has a different flag:

Transient state: The object does not have one

Persistent state: The primary key of the object has been assigned and is in

Free state: The primary key of this object has been assigned, but there is no rain

Fourth, business management

1. Transaction

Business generally refers to something to be done or done. In computer terms, a unit of program execution that accesses and possibly updates various data items in a database

1.1 Transaction Characteristics:

1) Atomicity: says that within a transaction is indivisible, either success or failure.

2) Consistency: it can be understood as the consistency of data changes before and after a transaction. For example, if Zhang SAN transfers 500 yuan to Li Si, it can be regarded as a transaction. After the transaction, If Zhang SAN loses 500 yuan, Then Li Si’s money must increase 500 yuan.

3) Isolation: it refers to the non-interference and influence between transactions, that is, the concurrent execution of transactions should be carried out in accordance with the continuous execution, non-interference execution (one after another). (Setting the isolation level of the database results in different isolation, see below)

4) Persistence: Simply speaking, once the transaction is successfully executed, it is persisted to the database.

1.2 Transaction isolation Level:

Transaction isolation levels from low to high are :(different isolation levels involve different concurrent access issues)



Read Uncommitted

: The lowest isolation level where nothing needs to be done and one transaction can read the uncommitted results of another transaction. All concurrent transaction problems can occur.



Read Committed

: Only after a transaction commits will its update results be seen by other transactions. Can solve the dirty read problem.



Repeated Read (MySQL default level)

: A read of the same data in a transaction is always the same regardless of whether other transactions operate on the data and whether the transaction is committed or not. It can solve dirty and unrepeatable reads.



Serialization

: Ideal true transaction isolation, where transactions are executed serialized at the highest isolation level at the expense of system concurrency. Can solve all the problems of concurrent transactions.

1.3 Concurrent Access Problems caused by Isolation Level:

Isolation level processing mentioned above

Serialization

Both have concurrent access issues, but serialization does not allow concurrent access (which is safe, but also extremely inefficient), so we generally don’t use it.

1)

Dirty read

(Drity Read)

: transaction

Have not been submitted

Update results if transaction

2)

Unrepeatable read

(Non-repeatable read)

Transaction concurrency change records

The easiest way to avoid this is to modify the record
Lock, which leads to increased lock competition, affecting performance.

3)

Phantom reading (virtual reading)

(Phantom Read)

If you want to learn front-end development, you can add groups:
To learn!