Java framework --- getting started with hibernate

Source: Internet
Author: User

Java framework --- getting started with hibernate
There are six core interfaces of the core interface Hibernate: Session, SessionFactory, Transaction, Query, Criteria, and Configuration. These six core interfaces are used in any development. Through these interfaces, you can not only access persistent objects, but also control transactions. The following describes these six core interfaces. The SessionSession interface is responsible for executing the CRUD operation on 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. SessionFactorySessionFactory 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. The TransactionTransaction interface is an optional API. You can choose not to use this interface. Instead, it 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 transplanted between different environments and containers. The QueryQuery interface allows you to easily query databases and persistent objects. It can be expressed in HQL or SQL statements of local databases. Query is often used to bind Query parameters, limit the number of Query records, and finally perform Query operations. The CriteriaCriteria interface is similar to the Query interface, allowing you to create and execute object-oriented standardized queries. It is worth noting that the Criteria interface is also lightweight and cannot be used outside the Session. The ConfigurationConfiguration interface 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. The advantage of hibernate is that Hibernate will process ing Java classes to use XML files, database tables and no need to write any line of code. Provides simple APIs for storing and retrieving Java objects directly from the database. If there is any change, you only need to modify the attributes of the XML file in the database or any table. Abstract unfamiliar SQL types and provide solutions to familiar Java objects. Hibernate does not require the application server to perform operations. Manipulate the complex association of database objects. Minimize access to and intelligently read policy databases. Provides simple data query. Hibernate configuration first download hibernate required package, I download is the hibernate-distribution-3.6.4.Final, extract the downloaded file, the directory structure is as follows. Copy the package in lib to the project. You can also use myeclipse to directly load the hibernate framework. Configuration File hibernate. cfg. xml <? Xml version = '1. 0' encoding = 'utf-8'?> <! DOCTYPE hibernate-configuration PUBLIC "-// Hibernate/Hibernate Configuration DTD 3.0 // EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"> <! -- Generated by MyEclipse Hibernate Tools. -->

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.