Hibernate Core API Detailed

Detailed Hibernate Core API:

Hibernate API for a total of six, are: Session, SessionFactory, Transaction, Query, Criteria and Configuration. You can access, transaction control of the persistent object through these interfaces.

  1. The Session
    the Session interface is responsible for the implementation of the persistent object CRUD operations (CRUD task is to complete the exchange with the database, contains a lot of common SQL statements). But note that the Session is not thread-safe. Meanwhile, Hibernate session is different from the JSP application HttpSession. When used herein the term session, in fact, it refers to the Hibernate session, and will be later referred to as user session HttpSession object.

  2. SessionFactory
    SessionFactory interface is responsible for initializing Hibernate. It acts as a proxy data storage source, and is responsible for creating Session objects. This uses the factory pattern. Note that SessionFactory not lightweight, because under normal circumstances, a project usually requires only a SessionFactory enough, when you need to operate more than one database, you can specify a SessionFactory for each database.

  3. Transaction
    Transaction Interface is an optional API, you can choose not to use this interface, replaced by Hibernate designers to write their own underlying transaction code. Transaction interface is an abstraction of the actual transaction implementation, and these implementations include JDBC transaction, JTA in UserTransaction, or even a CORBA transaction. The reason for this design is to allow developers to use a unified user interface matters, making their own projects can be easily ported between different environments and containers.

  4. Query
    Query Interface allows you to easily query the database and persistent objects, it can have two expressions: HQL language or local database SQL statements. Query is often used to bind query parameters, limit the number of query records, and eventually execute the query operation.

  5. Criteria
    Criteria Query interface very similar interface, allows the creation and implementation of a standardized object-oriented queries. It is noteworthy that Criteria interface is also lightweight, it can not be used outside Session.

  6. Configuration
    action is Hibernate Configuration class configuration, and it start. Hibernate during startup, the first instance of the class Configuration position location mapping document, reads the configuration, and then create a SessionFactory. Although Configuration class throughout the Hibernate project only plays a small role, but it is the first object encountered when starting hibernate.

Released four original articles · won praise 0 · Views 49

Guess you like

Origin blog.csdn.net/qq_41442590/article/details/85233321