Hibernate Object Persistence framework

Source: Internet
Author: User
Tags driver manager

Hibernate Object Persistence framework
JDBC :( Java Data Base Connectivity) java Database Connection

The java. SQL package provides JDBC APIs to write program code for accessing the database. common interfaces and classes include the following:

DriverManager: Driver manager, responsible for creating database Connection: stands for database Connection Statement: responsible for executing SQL statements PreparedStatement: responsible for executing SQL statements, with the function of pre-defined SQL statements ResultSet: indicates the query result set of an SQL query statement.
Programming thinking to manipulate the database. 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.

Hibernate has six core interfaces: Session, SessionFactory, Transaction, Query, Criteria, and Configuration.
Session interface:Executes the CRUD operation of the Persistent Object (the CRUD task is to complete the communication with the database, including many common SQL statements .). However, it should be noted that the Session object is non-thread-safe. At the same time, the Hibernate session is different from the HttpSession In the JSP application. Here, when session is used, it actually refers to the session in Hibernate, and later the HttpSession object will be called the user session.

SessionFactory interface: initializes Hibernate. It acts as a proxy for the data storage source and is responsible for creating Session objects. The factory model is used here. Note that SessionFactory is not lightweight, because generally, only one SessionFactory is required for a project. When you need to operate multiple databases, you can specify a SessionFactory for each database.

Transaction interface:Is an optional API, you can choose not to use this interface, instead is the underlying transaction processing code written by the Hibernate designer. The Transaction interface is an abstraction of the actual Transaction implementation. These implementations include JDBC transactions, UserTransaction in JTA, and even CORBA transactions. This design allows developers to use a unified transaction operation interface so that their projects can be easily moved between different environments and containers.

Query interface:This allows you to easily query databases and persistent objects. It can be expressed in two ways: HQL or SQL statements of the local database. Query is often used to bind Query parameters, limit the number of Query records, and finally perform Query operations.

Criteria interface:Similar to the Query interface, you can create and execute object-oriented standard queries. It is worth noting that the Query interface is also lightweight and cannot be used outside the Session.

Configuration interface:It is used to configure and start Hibernate. During Hibernate startup, the Configuration instance first locates the ing document, reads the configurations, and creates a SessionFactory object. Although the Configuration interface only plays a small role in the entire Hibernate project, it is every object encountered when hibernate is started.

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.