HibernatePreliminary Study
(1)Persistence: Two storage statuses of data on a computer:
Instantaneous status : Stored in memoryProgramData, the data disappears after the program exits, known as the Instantaneous State
Persistent status: The program data stored on the disk still exists after the program exits, which is called the persistent state of the program data.
Persistence is a mechanism for converting program data between the instantaneous and persistent states.
(2)ORMPrinciple:
ORM :
Object Relation Mapping Object link ing It is used to automatically map between a relational database and an object. Map Data Tables in the database to objects, that is, persistence classes. Operate relational databases in the form of objects. To reduce data persistence programming tasks during application development. Schematic:
HibernateIntroduction: Founder: Gavin king Hibernate is an open Source code Object relationship ing framework, which encapsulates JDBC very lightweight objects, so that Java programmers can use the object programming thinking to manipulate the database as they wish. Hibernate can be used in any situation where JDBC is used. It can be used in Java client programs or Servlet/JSP web applications. The most revolutionary is that, hibernate can replace CMP in the J2EE architecture of application EJB to fulfill the task of data persistence.
HibernateArchitecture:
Three important classes: Ø
Configuration class: Configuration Manages the configuration information of Hibernate and starts hibernate. The configuration class will read some basic information about the implementation of indignation when hibnernate is running. This information includes: Database driver, Database URL, database user name, Database User Password, database adapter (dialect) Ø
Session factory class: sessionfactory Is the factory that generates the session. It stores all the Mappings in the current database. It may be an optional second-level data cache, And it is thread-safe. However, it is a heavyweight Object and will overwrite a large amount of system resources during initialization. Generally, a project contains a sessionfactory. Ø
Session class: Session It is the core of database persistence operations in Hibernate and is responsible for all persistence operations in hibernate. It can be used to achieve basic addition, deletion, modification, and query. Note: The session is not thread-safe. Do not share a session with multiple threads.