Hibernate Object Persistence Framework

Source: Internet
Author: User
Tags driver manager

JDBC: (Java data Base Connectivity)Java database connection

The java.sql package provides the JDBC API through which you can write program code to access the database. The interfaces and classes that are used frequently include the following:

    • DriverManager: Driver Manager, responsible for creating database connections
    • Connection: representing the database connection
    • Statement: Responsible for running SQL statements
    • PreparedStatement: Responsible for running SQL statements with the ability to define SQL statements in advance
    • ResultSet: Query result set on behalf of SQL query statement


Hibernate (Java Object Persistence Technology):Hibernate is an open source object-Relational mapping framework that provides a very lightweight object Encapsulation of JDBC. Allows the Java program ape to use object programming thinking to manipulate the database as it pleases. Hibernate can be used in both Java client applications and in servlet/jsp Web applications, regardless of the use of JDBC. Most revolutionary of all, hibernate can replace CMP in the application of EJB's Java EE Architecture and complete the task of data persistence.

Hibernate has 6 core interfaces, namely: Session, Sessionfactory, Transaction, Query, criteria, and configuration.
Session Interface: responsible for running the persisted objectcrud Operations(The CRUD task is to complete the communication with the database, including very many common SQL statements.)

)。 However, it is important to note that the session object is non-thread safe. At the same time, Hibernate's session differs from the HttpSession in JSP applications. When the term "session" is used, it actually refers to the session in Hibernate. Later, the HttpSession object is called the user session.

Sessionfactory Interface: responsible for initializing hibernate . It acts as a proxy for the data storage source and is responsible for creating session objects.

The factory model is used here. It is important to note that Sessionfactory is not lightweight. Because of the normal situation. A project usually requires only one sessionfactory, and when you need to manipulate multiple databases, you can specify a sessionfactory for each database.

Transaction interface: is an optional API that can choose not to use this interface instead of the underlying transaction code written by Hibernate's designers themselves. The Transaction interface is an abstraction of the actual transaction implementation that includes JDBC transactions, usertransaction in JTA, and even CORBA transactions.

This design is designed to enable developers to use a single transactional interface, allowing their projects to move values easily between different environments and containers.



Query interface: It allows you to make queries to databases and persistent objects conveniently , and it can be expressed in two ways: the HQL language or the SQL statement of the local database.

Queries are often used to bind query parameters, limit the number of query records, and finally run query operations.

Criteria Interface: similar to the query interface, you agree to create and run an object-oriented, standardized query .

It is important to note that the query interface is also lightweight and cannot be used outside the session.

Configuration Interface: The function is to configure Hibernate and start it. During Hibernate startup. An instance of the Configuration class first locates the location of the mapped document. Read these configurations, and then create a Sessionfactory object. Although the configuration interface only plays a very small role throughout the Hibernate project, it is every object encountered when starting hibernate.

Copyright notice: This article blog original articles, blogs, without consent, may not be reproduced.

Hibernate Object Persistence Framework

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.