The advantages of Hibernate enterprise Framework using the Java EE Foundation

Source: Internet
Author: User

One, hibernate is the lightweight object encapsulation of JDBC, it is an independent object persistence layer framework, and app Server, and EJB have no inevitable connection. Hibernate can be used in any situation where JDBC can be used, such as database access code for Java applications, the implementation class of DAO interfaces, or even the code that accesses a database in BMP. In this sense, hibernate and EB are not a category of things, nor is there an either-or relationship.

Second, Hibernate is a framework closely related to JDBC, so hibernate compatibility and JDBC driver, and database have a certain relationship, but with its Java program, and app server has no relationship, there is no compatibility issues.

Third, hibernate can not be used directly compared to entity beans, only in the framework of the entire Java project can be compared. And even in the context of the overall software framework, Hibernate is also a substitute for JDBC, not a substitute for entity beans, let me list the frame structures I've listed n times:

The traditional architecture:

1 session Bean <-> Entity Bean <-> DB

To address the alternative architecture of performance barriers:

2 session Bean <-> DAO <-> JDBC <-> DB

The architecture that uses hibernate to improve the development efficiency of the above architecture:

3 session Bean <-> DAO <-> Hibernate <-> DB

The above 3 architectures are analyzed:

1. Memory consumption

The adoption of JDBC Architecture 2 is undoubtedly the most provincial memory, hibernate Architecture 3 times, EB's architecture 1 the worst.

2. Operation Efficiency

If JDBC code writes very well, the JDBC architecture is most efficient, but this is almost impossible in actual projects, requiring programmers to be very proficient in JDBC, using batch statements, adjusting preapredstatement batch size and fetch Size and so on, and if necessary, using result set cache and so on. In general, programmers can't do that. So the hibernate architecture shows the fastest running efficiency. EB's architecture is far less efficient.

3. Development efficiency

With the support of JBuilder and simple projects, EB architecture is the most efficient, JDBC second, hibernate the worst. However, in the case of large projects, especially the persistence layer relationship mapping is very complex, hibernate efficiency is amazing, jdbc second, and EB architecture is likely to fail.

4. Distributed, safety inspection, cluster, load balancing support

There is no difference between having SB as a facade,3 structure.

Four, EB and hibernate learning difficulty in where?

What is the difficulty of EB? Not on the complex XML configuration file, but on the use of EB slightly careless, there are serious performance barriers. So it's hard when you need 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 efficiency of EB operation. To do EB development, most of the programmer's energy has been put on EB's performance issues, but there is no more attention to their own focus on the main energy to consider the design of the object persistence layer.

Where is hibernate difficult? Not hibernate itself complex, in fact hibernate very simple, difficult in hibernate too flexible.

When you use EB to achieve the persistence layer, you will find that EB is too clumsy, clumsy to you have nothing to choose from, so you do not have to spend energy to design a plan, to balance the quality of the project, to consider the choice of options, because only the only solution in front of you, you can only do so, No choice.

Hibernate on the contrary, it is too flexible, the same problem, you can design at least more than 10 kinds of solutions to solve, so particularly puzzled, actually use this, or with that? What is the difference between these programs? What is the difference between their operating principles? Operating efficiency which is better? Light primary key generation, there are seven or eight options for you to choose, you are not embarrassed? Set properties can be set, you can use list, but also with bag, in the end which is high efficiency, you embarrassed not embarrassed? Query can use iterator, you can use list, which is good, what is the difference? Are you embarrassed? Composite PRIMARY key You can configure it directly in the HBM, or you can customize CustomerType, which is better? Are you embarrassed? For a table, you can choose a single map of an object, can also be mapped to a parent-child object, can also be mapped into two 1:1 objects, under what circumstances in which the scheme is better, you embarrassed?

This list can be listed until you don't want to see it anymore. When you are in front of countless dazzling plan, you will feel happy? Or is it sad? If you are a responsible programmer, then you will be careful to study the difference between each scenario, the efficiency of each program, the application of each scenario, you will feel that you have been caught in the pull out. If you are using EB, you have made a decision in the first second, there is no choice, such as collection properties, you can only use collection, if it is hibernate, you will be in bag,list and set between the hesitant, or even confused, the procedure has no way to write.

Related Article

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.