The Hibernate framework outlines how the &SSH framework works and processes __hibernate

Source: Internet
Author: User
Tags sessions

Hibernate is an open source Object relational mapping (Orm,object Rational Mapping) framework that has a very lightweight object encapsulation of JDBC, which maps Pojo to database tables and is a fully automated ORM framework, Hibernate can automatically generate SQL statements that automate, allowing Java programmers to manipulate the database with arbitrary object-programming thinking. Hibernate can be applied in any use of JDBC, either in Java client programs or in servlet/jsp Web applications, and, most of all, hibernate can replace CMP in an EJB-ee architecture, Complete the task of data persistence.

Core interface and class Hibernate core class and interface a total of 6, respectively: Session, Sessionfactory, Transaction, Query, criteria and configuration. These 6 core classes and interfaces are used in any development. Through these interfaces, not only can the persisted object be accessed, but also the transaction can be controlled.      The following 6 core interfaces and classes are described separately. The session Sessions session interface is responsible for the crud operations of the persisted objects (the CRUD task is to communicate with the database, including many common SQL statements). However, it should be noted that the session object is not thread safe. At the same time, Hibernate's session is different from the HttpSession in JSP application. Here when using the term session, in fact, refers to the hibernate in the sessions, and later will be the HttpSession object called the user.hibernatesessionfactoryThe Sessionfactory interface is responsible for initializing hibernate. It acts as a proxy for the data storage source and is responsible for creating the Session object. The factory model is used here. Note that sessionfactory is not lightweight, because typically a project requires only one sessionfactory, and you can specify a sessionfactory for each database when you need to manipulate multiple databases.hibernatetransactionThe Transaction interface is an optional API that allows you to choose not to use this interface and replace it with the underlying transaction code written by the Hibernate designer. The Transaction interface is an abstraction of the implementation of real transactions, including JDBC transactions, usertransaction in JTA, or even CORBA transactions. This design is designed to enable developers to use a unified transaction interface, so that their projects can be easily ported between different environments and containers.HibernatequeryThe query interface gives you easy access to databases and persistent objects, and it can be expressed in two ways: the HQL language or the SQL statement for the local database. Queries are often used to bind query parameters, limit the number of query records, and ultimately perform query operations.HibernatecriteriaThe criteria interface is very similar to the query interface, allowing for the creation and execution of object-oriented standardized queries. It is noteworthy that the criteria interface is lightweight, and it cannot be used outside of the session.hibernateconfigurationThe role of the Configuration class is to configure the Hibernate and to start it. During hibernate startup, instances of the Configuration class first locate the mapping document, read the configuration, and then create a Sessionfactory object. Although the configuration class plays only a small role in the entire Hibernate project, it is the first object that was encountered when the hibernate was started.SSH FrameworkSSH is an integrated framework for struts+spring+hibernate, a more popular open source framework for Web applications today. The system of integrated SSH framework is divided into four layers: presentation layer, business logic layer, data persistence layer and Domain module layer to help developers build clear, reusable and maintainable Web applications in the short term. It uses struts as the overall infrastructure of the system, responsible for the separation of MVC, in the model section of the Struts framework, controlling business jumps, leveraging the Hibernate framework to support the persistence layer, spring doing management, and managing struts and hibernate. By using object-oriented analysis method, we propose some models, implement these models as basic Java objects, then write the basic DAO (Data Access Objects) interface, and give the hibernate DAO implementation. Using the DAO class implemented by Hibernate architecture to transform and access Java classes and databases, and finally managed by spring, the basic business process of managing struts and hibernate systems is: In the presentation layer, the interface is implemented first through the JSP page, which is responsible for Request and Delivery response (Response), then struts delegates the request received by Actionservlet to the appropriate action processing according to the configuration file (Struts-config.xml). In the business layer, the spring IOC container that manages the service components is responsible for providing the action with the business model component and the component's collaboration Object data Processing (DAO) component to complete the business logic and providing container components such as transaction processing, buffer pooling to improve system performance and ensure data integrity.     In the persistence layer, it relies on the hibernate mapping and database interaction, processing the data requested by the DAO component, and returning the processing results. Frame structureSSH Framework Struts1      struts provides the corresponding components for both Model,view and controller.      Actionservlet, this class is the core controller of STRUTS1, which is responsible for intercepting requests from users.      action, this class is usually provided by the user, who is responsible for receiving requests from Actionservlet, and calls the business logic method of the model to process requests based on the request, and returns the processing results to the JSP page display.        Model section:      consists of actionform and JavaBean, Where Actionform is used to encapsulate the user's request parameters into a Actionform object that is Actionservlet forwarded to the action,action to process the user's request based on the request parameters in the Actionform. The      JavaBean encapsulates the underlying business logic, including database access.       View section:     This section uses JSP (or HTML, PHP ...). Achieve     struts provides a rich library of tags, through the tag library can reduce the use of scripts, custom tag library can be implemented with the model of effective interaction, and increase the reality of the function. Corresponds to the JSP portion of the above figure.       controller components:     Controller components are composed of two parts-system core controller, business logic controller.    system core Controller, corresponding to the top of the Actionservlet. The controller inherits the HttpServlet class and can therefore be configured as a callout servlet. The controller is responsible for intercepting all HTTP requests and then deciding whether to transfer to the business logic controller based on the user's request.     Business Logic Controller, responsible for processing user requests, does not have the ability to handle itself, but call model to complete processing. Corresponds to the action section.     SSH framework Spring      Spring is an open source framework that was created by Rod Johnson. It is created to address the complexity of enterprise application development. Spring uses basic JavaBean to accomplish things that were previously only possible by EJB. However, the purpose of spring is not limited to server-side development. In terms of simplicity, testability, and loose coupling, any Java application can benefit from spring.       Purpose: To solve the complexity      function of enterprise application development: Use basic JavaBean instead of EJB, and provide more enterprise application function       Scope: Any Java application       in simple terms, Spring is a lightweight control inversion (IoC) and aspect-oriented (AOP) container framework.      Lightweight-Spring is lightweight both in terms of size and cost. The complete spring framework can be published in a jar file that is only 1MB large. and the processing overhead required by spring is negligible. In addition, Spring is non-intrusive: Typically, objects in a spring application do not depend on a particular class of spring. Control reversal--spring facilitates loose coupling through a technology called Control reversal (IoC). When the IOC is applied, other objects that an object relies on are passed in passively, rather than the object itself creating or locating dependent objects. You can think of the IOC as the opposite of Jndi-not that the object looks for dependencies from the container, but rather that the container is actively passing the dependency to it when the object is initialized. Aspect-oriented--spring provides rich support for aspect-oriented programming, allowing for cohesive development through separation of application business logic and system-level services such as audit (auditing) and transaction (transaction) management. Application objects only implement what they should do--complete the business logic--that's all. They are not responsible (or even conscious) of other system-level concerns, such as logs or transactional support. The       container--spring contains and manages the configuration and lifecycle of the Application object, in the sense that it is a container where you can configure how each of your beans is created-based on a configurable prototype (prototype), Your bean can create a separate instance or generate a new instance every time you need it-and they are likeWhat is related to each other. However, spring should not be confused with traditional heavyweight ejb containers, which are often bulky and unwieldy and difficult to use.       Framework--spring can be a simple component configuration, combination of complex applications. In spring, application objects are declaratively grouped, typically in an XML file. Spring also provides a number of basic functions (transaction management, persistence framework integration, and so on) that leave the development of application logic to you. All of Spring's features enable you to write cleaner, more manageable, and more testable code. They also provide basic support for the various modules in spring.      SSH framework Hibernate       Hibernate is an open source object-relational mapping framework that has a very lightweight object encapsulation for JDBC, allowing Java programmers to manipulate the database with arbitrary object-programming thinking. Hibernate can be applied to any use of JDBC, either in Java client programs or in servlet/jsp Web applications, and, most of all, hibernate can replace CMP in an EJB-EE architecture, complete with The task of data persistence. There are 5 core interfaces of       hibernate, namely session, Sessionfactory, Transaction, query and configuration. These 5 core interfaces will be used in any development. Through these interfaces, not only can the persisted object be accessed, but also the transaction can be controlled. The following five core interfaces are described separately. · Session Interface: The session interface is responsible for performing crud operations on the persisted object (the CRUD task is to communicate with the database, including many common SQL statements.) )。 However, it should be noted that the session object is not thread safe. At the same time, Hibernate's session is different from the HttpSession in JSP application. Here when using the term session, in fact, refers to the hibernate in the sessions, and later will be the HttpSession object called the user.      Sessionfactory interface: Sessionfactory interface is responsible for initialization of hibernate. It acts as a proxy for the data storage source and is responsible for creating the Session object. The factory model is used here. Note that sessionfactory is not lightweight, because typically a project requires only one sessionfactory, and you can specify a sessionfactory for each database when you need to manipulate multiple databases.     Configuration interface: The configuration interface is responsible for configuring and starting Hibernate, creating Sessionfactory objects. During hibernate startup, instances of the configuration class first locate the mapping document location, read the configuration, and then create the Sessionfactory object.    Transaction interface: The transaction interface is responsible for transaction-related operations. It is optional, and developers can also design their own underlying transaction processing code.     Query and the criteria interface: query and the criteria interface are responsible for performing various database queries. It can be expressed using either the HQL language or the SQL statement.

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.