[Turn] on the meaning and essence of the integration of SSH (struts,spring,hibernate three frames)

Source: Internet
Author: User
Tags to domain

How hibernate works
principle:
1. Read and parse the configuration file
2. Read and parse mapping information, create Sessionfactory
3. Open Sesssion
4. Create Transaction transation
5. Persistent Operation
6. Commit a transaction
7. Close Session
8. Close Sesstionfactory

Why to use:
1. The code for JDBC access to the database is encapsulated, which greatly simplifies the tedious repetitive code of the data access layer.

2. Hibernate is a JDBC-based, mainstream persistence framework that is an excellent ORM implementation. He simplifies the coding of the DAO layer to a great extent

3. Hibernate uses the Java reflection mechanism rather than the bytecode enhancer to achieve transparency.

4. Hibernate performs very well because it is a lightweight framework. The flexibility of the mapping is excellent. It supports a variety of relational databases, from one-to-one to many-to-many complex relationships.

2. How does hibernate delay loading?
1. Hibernate2 Deferred load implementation: a) collection of entity object B) (Collection)

2. Hibernate3 provides properties for lazy loading functions

when hibernate is querying the data, the data does not exist in memory, and when the program actually operates on the data, the object exists in memory, and the delay is loaded, which saves the server's memory overhead and improves the performance of the server.

3. How do the relationships between classes be implemented in hibernate? (e.g. one-to-many, many-to-many relationships)

the relationship between classes and classes is mainly manifested in the relationship between tables and tables, they operate on objects, and in our program we map all the tables and classes together, through the Many-to-one, One-to-many, Many-to-many,

4. The caching mechanism of hibernate

1. Internal cache exists Hibernate is also called a first-level cache, belongs to the application of the thing-level cache

2. Level Two cache:
a) application and caching
b) Distributed cache
conditions: Data is not modified by third parties, data size is acceptable, data update frequency is low, the same data is frequently used by the system, non-critical data
c) Implementation of third-party caches

5. How hibernate is queried
Sql, Criteria,object comptosition
HQL:
1. Attribute Query
2, parameter query, named parameter query
3. Related Queries
4, paging query
5. Statistical functions

6. How to optimize hibernate?
1. Use bidirectional one-to-many associations without using
2. Flexible use of unidirectional one-to-many associations
3. Do not use one-to-many substitution
4. Configure the object cache without using the collection cache
5. One-to-many collection using bag, multi-set using Set
6. Inheriting classes using explicit polymorphism
7. Table fields are less, tables associated not afraid of more, there is a level two cache backing

How struts works

struts working mechanism? Why use struts?
working mechanism:
the work flow of struts:
when the Web app starts, it loads the initialization actionservlet,actionservlet from
struts-config.xml files to read configuration information and store them in various configuration objects
When Actionservlet receives a customer request, the following process is executed.
-(1) Retrieval and user request matching actionmapping instance, if not present, return the request path invalid information;
-(2) If the Actionform instance does not exist, create a Actionform object and save the form data submitted by the client to the Actionform object;
-(3) Determine if form validation is required based on configuration information. If validation is required, call Actionform's validate () method;
-(4) If Actionform's Validate () method returns null or returns a Actuiberrors object that does not contain actionmessage, the form validation is successful;
-(5) Actionservlet determines which action to forward the request to, based on the mapping information contained in the actionmapping, and if the corresponding action instance does not exist, create the instance first and then invoke the Execute () method of the action;
-(6) The Execute () method of the action returns a Actionforward object that actionservlet the JSP component to which the client request is forwarded to the Actionforward object;
-(7) The Actionforward object points to the JSP component to generate a Dynamic Web page, which is returned to the customer;

Why to use:
the advent of JSP, Servlet, and JavaBean technology gives us the possibility to build powerful enterprise application systems. But the systems built with these techniques are very fanluan, so on top of that, we need a rule, a rule that organizes these technologies, and that is the framework in which struts emerges.

struts-based applications consist of 3 types of components: Controller components, model components, view components

8. How is the validate framework of struts validated?
Configure specific error prompts in the struts configuration file, and then invoke the Validate () method in Formbean.

9. The design pattern of struts
MVC mode: Actionservler is loaded and initialized when the Web application starts. When a user submits a form, a configured Actionform object is created and populated with the corresponding data in the form. Actionservler determines whether form validation is required based on the settings configured for the Struts-config.xml file, and if necessary, select the action to which the request is sent if the Validate () validation is called Actionform, if the action does not exist , Actionservlet creates the object first and then invokes the Execute () method of the action. Execute () Gets the data from the Actionform object, completes the business logic, returns a Actionforward object, actionservlet the client request to the JSP component specified by the Actionforward object, The Actionforward object specifies that the JSP generates a dynamic Web page that is returned to the customer.


How Spring Works
1.spring MVC requests that all requests be submitted to Dispatcherservlet, which will delegate the other modules of the application system responsible for the actual processing of the request.
2.DispatcherServlet queries one or more handlermapping to find the controller that handles the request.
3.DispatcherServlet request Submit to target Controller
4.Controller After the business logic is processed, it returns a Modelandview
5.Dispathcher querying one or more viewresolver view resolvers, locating the View object specified by the Modelandview object
6. The View object is responsible for rendering back to the client.

Why use:
{AOP allows developers to create non-behavioral concerns, called crosscutting concerns, and insert them into application code. With AOP, public services (such as logs, persistence, transactions, and so on) can be decomposed into facets and applied to domain objects without increasing the complexity of the object model of the domain object.
IOC allows you to create an application environment where objects can be constructed, and then pass their collaboration objects to those objects. As the word inversion shows, the IOC is like the reverse JNDI. Not using a bunch of abstract factories, service locators, single elements (singleton), and direct constructs (straight construction), each object is constructed with its collaboration objects. Therefore, the collaboration object (collaborator) is managed by the container.
Spring even an AOP framework, is also an IOC container. The best part of Spring is that it helps you replace objects. With Spring, you simply add dependencies (collaboration objects) with the JavaBean property and configuration file. You can then easily replace collaboration objects with similar interfaces when you need them. }




The Spring Framework is a layered architecture consisting of 7 well-defined modules. The Spring modules are built on top of the core container, and the core container defines how the beans are created, configured, and managed, as shown in 1.

each module (or component) that makes up the Spring framework can exist separately or be implemented in conjunction with one or more other modules. The functions of each module are as follows:

☆ Core Container: The core container provides the basic functions of the Spring framework. The main component of the core container is Beanfactory, which is the implementation of the factory pattern. The beanfactory uses the inversion of control (IOC) pattern to separate the application's configuration and dependency specifications from the actual application code.

☆spring Context: The spring context is a configuration file that provides contextual information to the spring framework. The Spring context includes enterprise services such as JNDI, EJB, e-mail, internationalization, checksum scheduling.

☆spring AOP: With the configuration management feature, the Spring AOP module directly integrates aspect-oriented programming capabilities into the spring framework. Therefore, it is easy to enable any object managed by the Spring framework to support AOP. The spring AOP module provides transaction management services for objects in spring-based applications. By using Spring AOP, you can integrate declarative transaction management into your application without relying on EJB components.

the ☆spring dao:jdbc DAO Abstraction Layer provides a meaningful exception hierarchy that can be used to manage exception handling and error messages thrown by different database vendors. The exception hierarchy simplifies error handling and greatly reduces the number of exception codes that need to be written (such as opening and closing connections). Spring DAO's JDBC-oriented exception conforms to the common DAO exception hierarchy.

The ☆spring orm:spring Framework inserts several ORM frameworks, providing an ORM object-relational tool that includes JDO, Hibernate, and IBatis SQL Map. All of these conform to Spring's common transaction and DAO exception hierarchies.

☆spring Web module: The Web context module is built on top of the application context module and provides the context for Web-based applications. Therefore, the Spring framework supports integration with Jakarta Struts. The Web module also simplifies the process of working with multipart requests and binding request parameters to domain objects.

☆spring MVC framework: The MVC Framework is a full-featured MVC implementation of building WEB applications. With the policy interface, the MVC framework becomes highly configurable, and MVC accommodates a large number of view technologies, including JSP, Velocity, Tiles, IText, and POI.

The functionality of the Spring framework can be used in any Java EE server, and most features are also available in an out-of-management environment. The core point of Spring is to support reusable business and data access objects that are not tied to a particular Java EE service. There is no doubt that such objects can be reused across different Java EE environments (Web or EJB), standalone applications, and test environments.

IOC and AOP

the basic concept of control reversal mode (also known as dependency intervention) is that you do not create objects, but describe how they are created. The code does not directly connect to objects and services, but describes in the configuration file which component requires which service. Containers (which are IOC containers in the Spring framework) are responsible for linking these together.

in a typical IOC scenario, the container creates all the objects and sets the necessary properties to connect them together, deciding when to invoke the method. The following table lists an implementation pattern for the IOC.

PS: Good place to say welcome to shoot bricks--

[Turn] on the meaning and essence of the integration of SSH (struts,spring,hibernate three frames)

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.