This article mainly introduces the advantages and disadvantages of hibernate, struts, and spring. The following is a brief description of this article, hoping to help you learn and work.
The Struts framework has the advantages of modular components, flexibility and reusability, and simplifies the development of MVC-based Web applications.
Like many Apache projects such as Tomcat and turbine, Struts is an open-source software, which has a major advantage. This allows developers to gain a deeper understanding of their internal implementation mechanisms.
In addition, the advantages of struts are mainly embodied in two aspects: taglib and page navigation. Taglib is a struts tag library, which can be used flexibly to greatly improve development efficiency. In addition to common JSP tags, JSP developers in China rarely develop their own tags. Struts may be a good starting point.
As for page navigation, I think that will be a future direction. In fact, this will make the context of the system clearer. With a configuration file, you can grasp the relationship between all parts of the system, which is of great benefit for later maintenance. This advantage is especially evident when another group of developers take over the project.
In addition, Struts is a "standard" (many success stories) in the industry, with rich learning resources and excellent HTML tags.
Taglib is a major advantage of struts, but for beginners, it requires a continuous learning process and even disrupt the habit of writing web pages. However, when you get used to it, you will think it is really great.
Struts divides the controller of MVC into three parts. The structure is clearer while the complexity of the system is also increased.
Actionforms is inconvenient to use and cannot perform unit tests (strutstestcase can only be used for integration)
Like many Apache projects such as Tomcat and turbine, Struts is an open-source software, which has a major advantage. This allows developers to gain a deeper understanding of their internal implementation mechanisms. The struts open source framework is created to make it easier for developers to build Web applications based on Java Servlet and JavaServer Pages (JSP) technology. The Struts framework provides a unified standard framework for openers. By using struts as the basis, developers can focus more on the business logic of applications. The Struts framework is a Model-View-controller (MVC) implementation that uses Java Servlet and JavaServer Pages technology.
1. Implement the MVC mode with a clear structure, allowing developers to focus only on the implementation of business logic.
2. There are a variety of tags that can be used. The struts tag Library (taglib) can be used flexibly to greatly improve development efficiency. In addition to common JSP tags, JSP developers in China rarely develop their own tags. Struts may be a good starting point.
3. page navigation: page navigation will be a future direction. In fact, this will make the system context clearer. With a configuration file, you can grasp the relationship between all parts of the system, which is of great benefit for later maintenance. This advantage is especially evident when another group of developers take over the project.
4. Provides the exception handling mechanism.
5. Database Connection Pool Management
6. Support for i18n
1. When you go to the presentation layer, You need to configure forward. Every time you go to the presentation layer, I believe most of them are directly forwarded to JSP. When it comes to redirection, You need to configure forward, if there are ten JSP display layers, you need to configure struts for ten times, and sometimes directories and files need to be modified again. Note that after each configuration modification, it is required to re-deploy the entire project, and the servers such as the replicate must also be restarted. If the business changes complicated and frequent systems, such operations are simple and unimaginable. This is the case now. We can imagine how much trouble I have with hundreds of people using our system online at the same time.
2. Struts action must be thread-safe. It only allows one instance to process all requests. Therefore, all resources used by action must be synchronized in a unified manner, which causes thread security issues.
3. The test is inconvenient. Every action of Struts is coupled with the web layer, so that its test depends on the Web container, and unit test is difficult to implement. However, there is a JUnit extension tool struts testcase which can implement unit testing.
4. type conversion. Struts formbean regards all data as the string type. It can use the tool commons-beanutils for type conversion. However, the conversion is at the class level, and the conversion type cannot be configured. It is also very difficult to return error messages during type conversion to users.
5. The servlet dependency is too strong. Struts must depend on servletrequest and servletresponse when processing the action, and it cannot get rid of the servlet container.
6. In terms of front-end Expression Language, Struts integrates jstl, so it mainly uses the jstl Expression Language to obtain data. However, the expression language of jstl is very weak in collection and index attributes.
7. It is difficult to control the execution of an action. Struts creates an action. It is very difficult to control the execution sequence of the action. You even need to write the servlet again to meet your functional requirements.
8. Pre-and Post-action processing. Struts uses class-based hierarchies to process actions. It is difficult to perform operations before and after action processing.
9. Insufficient event support. in struts, a form corresponds to an action class (or dispatchaction). In other words, in struts, a form corresponds to only one event, struts is called Application Event. Application event is a coarse-grained event compared with component event.
Hibernate is an open-source object relationship ing framework that encapsulates JDBC objects in a lightweight manner, so that Java programmers can use the object programming thinking to manipulate the database as they wish.
Hibernate can be used in any scenario where JDBC is used. It can be used in both Java client programs and Servlet/JSP web applications. The most revolutionary thing is that, hibernate can replace CMP in the J2EE architecture of application EJB to fulfill the task of data persistence.
Most development organizations often create independent data persistence layers. Once the underlying data structure changes, it will be very costly to modify the rest of the application to adapt to this change. Hibernate fills this gap in time and provides an easy-to-use and efficient object relationship ing framework for Java applications. Hibernate is a lightweight persistence framework with rich functions.
1. hibernate uses the Java reflection mechanism instead of the bytecode enhancement program to achieve transparency.
2. hibernate has excellent performance because it is a lightweight framework. The flexibility of ing is excellent.
3. It supports various relational databases, from one-to-one to many-to-many complex relationships.
Disadvantages:It limits the object model you are using. (For example, a persistence class cannot be mapped to multiple tables.) its unique interface and poor market share are also disturbing. However, hibernate also mitigated these risks with its powerful development momentum. Other open-source Persistence frameworks also have some, but none of them have the market impact such as hibernate.
I am a little excited and hope to understand that I don't feel unhappy because someone has criticized hibernate, but because the opinions in the post really make me feel ridiculous. No matter whether Hibernate is good or not, I only feel sorry that I cannot find a real high-level comment on hibernate in the Chinese forum. There is a hot thread about hibernate on TSS, which has been followed by several hundred posts, including the CTO of hibernate authors Gavin and Lido JDO. There have been some heated debates on JDO and hibernate, I have patiently read it once and still have not found any really powerful attacks against hibernate. The so-called attacks are nothing more than a configuration tool for hibernate without the support of commercial companies, there is no such reason as standardization.
My comments are as follows:
1. Hibernate is a lightweight JDBC object encapsulation. It is an independent object persistence layer framework and has no necessary connection with app server and EJB. Hibernate can be used in any situations where JDBC can be used, such as the database access code of Java applications, the implementation class of Dao interfaces, and even the code for accessing the database in BMP. In this sense, Hibernate and EB are neither a category nor a relationship between them.
2. Hibernate is a framework closely related to JDBC, so the compatibility of Hibernate and the JDBC driver have a certain relationship with the database, but it is related to the Java program that uses it, it has nothing to do with the app server, and there is no compatibility problem.
3. hibernate cannot be used to compare it directly with Entity Bean. It can be compared only in the framework of the entire J2EE project. In addition, even in the overall framework of the software, Hibernate emerged as a replacement for JDBC, rather than an alternative to Entity Bean. Let me repeat the framework structure that I have already listed n times:
1) Session Bean <-> Entity Bean <-> DB
Alternative architecture to solve performance barriers:
2) Session Bean <-> Dao <-> jdbc <-> DB
Use hibernate to improve the development efficiency of the above architecture:
3) Session Bean <-> Dao <-> hibernate <-> DB
Analyze the above three architectures:
1. memory consumption: JDBC architecture 2 is undoubtedly the most memory-saving, Hibernate architecture 3 is the second, and EB architecture 1 is the worst.
2. Operational Efficiency: If JDBC code writing is very optimized, the JDBC architecture runs most efficiently, but in actual projects, this is almost impossible. This requires programmers to be very proficient in JDBC, use the batch statement to adjust parameters such as the batch size and fetch size of the preapredstatement, and use the result set cache when necessary. In general, programmers cannot do this. Therefore, the hibernate architecture shows the fastest running efficiency. EB's architecture efficiency will be very poor.
3. Development efficiency: with the support of JBuilder and simple projects, EB architecture has the highest development efficiency, followed by JDBC, and hibernate has the worst. However, in large projects, especially when the persistent layer relationship ing is complex, Hibernate is highly efficient, followed by JDBC, and EB architecture is likely to fail.
4. distributed, security check, cluster, and Server Load balancer support
Because there is Sb as a facade, there is no difference between the three architectures.
What are the learning difficulties of EB and hibernate? Where is EB difficult? Rather than complex xml configuration files, EB may suffer from severe performance barriers due to a slight carelessness. Therefore, it is difficult for you to learn a lot of EJB Design Patterns to avoid performance problems. You need to learn the configuration of APP server and EB to optimize the running efficiency of EB. For EB development, most of the programmer's energy has been put on EB's performance problems, instead, you can focus more on the design of the Object persistence layer.
What is the difficulty of hibernate? Not the complexity of hibernate itself. In fact, Hibernate is very simple, and it is difficult to be too flexible in hibernate.
When you use EB to implement the persistent layer, you will find that eb is too clumsy, so you have no choice at all, so you don't have to spend any energy designing a solution, balancing the quality of the solution, and worrying about which solution to choose, because only the only solution is in front of you. You can only do this, no choice.
On the contrary, Hibernate is too flexible. You can design at least a dozen solutions to solve the same problem, so it is especially difficult to use it? What are the differences between these solutions? What are their operating principles? Which one is more efficient? If you generate a primary key, there are seven or eight solutions for you to choose from? Set, list, and bag can be used for set attributes. Which efficiency is high? Iterator can be used for queries, list can be used, which is better, what is the difference? Are you embarrassed? You can configure the composite primary key directly in HBM or customize the customertype. Which one is better? Are you embarrassed? For a table, you can select a single ing object, or map it to a parent-child object, or two objects. Which solution is better, are you embarrassed?
This list can be listed until you don't want to see it again. When there are countless dazzling solutions in front of you, will you feel happy? Or sad? If you are a responsible programmer, you will certainly carefully study the differences between each solution, the efficiency of each solution, and the application scenarios of each solution, you will feel that you are already in and cannot be pulled out. If you use EB, you have made the decision in the first second, and you have no choice at all. For example, you can only use collection for set attributes. If it is hibernate, you will be in the bag, there is no way to write a list or set.
It is an open-source project and is currently very active. It is based on the IOC (inversion of control, reverse control) and AOP architecture multi-layer J2EE system framework, but it does not force you to use spring in each layer, because it is very modular and allows you to choose to use one of its modules as needed; it implements very elegant MVC and provides unified interfaces for different data access technologies. IOC makes bean Assembly easy, provides concise AOP and implements transcation management accordingly.
1. Spring can effectively organize your intermediate layer objects, whether or not you choose to use EJB. If you only use struts or other frameworks specially designed for J2EE APIs, spring is committed to solving the remaining problems.
2. Spring can eliminate the frequent use of Singleton in many projects. Based on my experience, this is a big problem. It reduces the testability and object-oriented level of the system.
3. By processing configuration files in the same way between different applications and projects, spring can eliminate the need for Attribute files in various custom formats. I was puzzled by the magic attribute or system attribute that a class was looking for. So I had to read javadoc or even the source code? With Spring, you just need to look at the JavaBean attribute of the class. The use of inversion of control (discussed below) helps to simplify the process.
4. by reducing the cost of interface programming rather than class programming to almost none, spring can promote good programming habits.
5. Spring is designed to minimize the reliance on its APIs for Applications created using it. Most business objects in spring applications do not depend on spring.
6. applications built using spring are easy to perform unit tests.
7. Spring makes the use of EJB an implementation choice, not an inevitable choice of the application architecture. You can use pojos or local ejbs to implement business interfaces without affecting the calling code.
8. Spring helps you solve many problems without using EJB. Spring can provide an EJB replacement, which is suitable for many web applications. For example, spring can use AOP to provide declarative transaction management instead of using EJB containers. If you only need to deal with a single database, you do not even need a JTA implementation.
9. Spring provides a consistent framework for data access, whether using JDBC or O/R mapping products (such as Hibernate ).
Spring does allow you to solve your problem through the simplest and most feasible solution. This is of great value.
The number of users is small, the JSP needs to write a lot of code, the controller is too flexible, the lack of a public controller, the configuration file is more difficult to maintain, if the configuration file is chaotic, maintenance is basically a disaster; the configuration file is also a double-edged sword: it provides flexibility, increases maintenance difficulty, and does not support distributed access, distributed transactions, and clusters. These are the advantages of EJB 3, however, spring is not currently supported. There is only one company providing spring containers (interface21). In other words, it is a non-standard technology monopolized by some companies, you cannot change the server of a vendor like EJB. Spring does not have a second company.