Comparison between hibernate, JDBC, and EJB
Favorites
Transferred from forum.javaeye.com
I,
Hibernate is a lightweight object encapsulation of JDBC. It is an independent object persistence layer framework
Server is not necessarily related to EJB. Hibernate can be used in any situations where JDBC can be used, such as Java application database access code and Dao Interface
Implementation class, or 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.
III,
Hibernate cannot be used directly with Entity
Bean can be compared only in the framework of the entire J2EE project. And even in the overall framework of the software, Hibernate also emerged as a replacement for JDBC.
This is not an alternative to Entity Bean. Let me repeat the frame structure that I have already listed n times:
Traditional Architecture:
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,
Running 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 and use it.
Adjust the batch size and fetch of the preapredstatement statement.
Size and other parameters, 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.
4. Where are the learning difficulties of EB and hibernate?
EB
Where is the difficulty? 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.
XI app
Server and EB configuration to optimize the running efficiency of EB. In EB development, most of the programmer's energy has been put on EB's performance problems, but it is not focused on itself.
Focus 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.
Hibernate
On the contrary, it is too flexible. For the same problem, you can design at least a dozen solutions to solve it. So it is especially difficult to use it? What are the differences between these solutions? Their operation
What is the difference in the line principle? 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 one is highly efficient? Iterator can be used for queries, list can be used, which is better, what is the difference? Are you embarrassed? You can directly configure the compound primary key in HBM,
You can also customize mermertype. Which one is better? Are you embarrassed? For a table, you can map a single object to a parent-child object or two objects.
Under what circumstances is it better to use a object?
This list can be listed until you don't want to see it again. When there are countless
You will feel happy when you are dazzled? Or sad? If you are a responsible programmer, you will carefully study the differences between each solution, the efficiency of each solution, and the applicability of each solution.
On the occasion, 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 example
If Hibernate is used, you will hesitate between bag, list, and set. If you are not clear about it, the program cannot be written.