Hibernate FAQ

xiaoxiao2021-03-05  21

The following article is just letting everyone know the advantages and future of Hibernate, there is no need to learn to see your actual needs, but it is recommended that you have time to study if you can use it better. If your foundation is not firm, please do three. Hibernate FAQ beginners must read! 1. What is Hibernate? Hibernate is an excellent development source code Java object persistent layer lightweight package frame, which can be used to replace most of the JDBC code in the Java application, or can be integrated into the J2EE system as a persistent layer frame. 2, what is the official website of Hibernate? Http://www.hibernate.org/3, Hibernate is developed? GAVIN KING 4, Hibernate download address? Http://sourceforge.net/projects/Hibernate/ 5, where is Hibernate? Http://www.hibernate.org/5.html 6, the current stable version of Hibernate is Hibernate2.0.3 7, Hibernate has a special forum? Official Forum (English) http://forum.hibernate.org/ Domestic Forum (Chinese) http://forum.hibernate.org.cn/ 8, Hibernate has routines? Http://www.hibernate.org/30.html ------------------------------------- ---------------------- Hibernate is easy, and I don't dare to boast. I also felt very hard when I saw Hibernate documentation, but I didn't feel hard because Hibernate was difficult to master, because Hibernate documents were all experience and best practices in persistent layer design. The Hibernate document is accurately, most of the content is on the persistent layer design of the object, not simple hibernate, using the problem to check Java DOC is enough. So learning hibernate, mainly in the design model of the lasting layer, if you finish the Hibernate document, all day will only mention those Hibernate configuration issues, Hibernate's class calls, I think this kind of person has not really true Getting started, it is white. My configuration for Hibernate is not particularly sure, and each time I write HBM, I have to check with a little bit of document; the type call parameters don't remember, and the write code is also available to Java DOC. But when I learned Hibernate, I concentrated all energy to understand the principle of Hibernate, concentrate on the principles and techniques that the persistent layer design should grasp, these are the most reused things. It is not exaggerated, I have learned Hibernate, I have improved the JDBC programming, not to mention the frame design of the J2EE architecture's persistence layer, basically in the chest, even if the API will be changed in the future. With hibernate, you can use JDO, CASTOR what, these experiences are used. Learning Hibernate is mainly how to configure Hibernat, how to generate HBM files with tools, if you focus on it, basically equal to white learning.

Hibernate's essence is that there is no longer-compared lavivious object persistent layer design. These persistent layer design experience will not lose because you don't have to use hibernate, I have learned Hibernate, which has been clearly felt that the long-lasting layer design capacity has grown a lot of experience. These experiences can be used in Java, and it is also the same on the .NET. So the study of Hibernate configuration, I just simply look at it, I know it, I will check it there, I don't look at it, I can't see it, so I'm working, master the Hibernate configuration, you can use Hibernate To replace JDBC write programs, it is enough for 3 days. I think 3 days is not a very luxurious learning price for you. Why do I emphasize the Hibernate's persistent layer design concept? Then look at your ideal is to do a programmer for a lifetime? Or do you want to develop in a higher direction? From the perspective of pure technology, the highest point of career development is "System Architect". Is Bill Gates not called Microsoft's chief system architect? The SYSTEM ARCHITECT job requires your learning and comprehension, if you can't use the design experience you get to Hibernate to other places, then you have failed, and there is no qualification to make System Architect. Regardless of JDO, Hibernate is good, Toplink is good, COCOBASE is also, or CASTOR, or what Torque, OJB, software use and configuration method can be different, but in nature is ORM, it is a long time for JDBC Layer package, so do not leave the Zong, if you completely learn and master Hibernate for 1 month, then you should learn ojb's time should not exceed 1 week, because you have already designed objects. However, the chest, what you need is just familiar with the OJB API and configuration, as for how to use OJB for a long-lasting layer, you have already been familiar with it. So when you have more than two ORMs, you should be able to limit the limitations of the ORM software that are suitable for your project, this is the level of SYSTEM ARCHITECT. By taking a part of the novel, Zhang Wuji learning Taiji sword, only remember the sword, not remembering the sword, this is the real master, and the low hands will only go to learn the sword, but not to understand the sword The sword behind, so it is a low hand in a lifetime, never truly learn Taiji swords. So Zhou saw Zhang Sanfeng's second demonstration Taiji sword, and the move is completely different, it is another set of things, in essence. Learning Hibernate does not want to learn a variety of five-way tools to learn, focus on its object of persistent layer design. -------------------------------------------------- ------------ I will talk about why I learned Hibernate, I hope to be a little inspirated for everyone. In the process of many of the projects I have done, I have always had a unresolved issue in troubled me, that is the development of persistence. The development of persistence layers is generally either with CMP or use JDBC DAO.

CMP does not have to be said, it is a failed practice for me, and JDBC Dao has a lot of difficulties. I am very difficult to make the relationship of the relationship table to the relationship of the lasting object, which is mainly reflected. The relationship between the multi-table cannot be directly mapped to the map of the persistent object, which may be a table mapping multiple persistent objects, which may be multiple tables to map a persistent object, and some of the tables are mapped to one Persistent objects, but other fields are mapped to other persistent objects. And even if these problems are processed, you can't program a lasting object (PO) in the way, because there is a 1: n relationship's persistent object's query is actually 1 N times to the database of SQL, I have A failure layer design, the result is that a query of a lot of other lasting objects is 5N 1 time SQL, the speed is slow, and finally, the entire modification of the underlying design is completely abandoned, it is completely abandoned. Follow the table fields. But this is very uncomfortable, because the design is designed from demand, the system is designed, and the result is to the detailed design phase, and it is restricted by the persistent layer mapping problem, and has to modify the design plan upstairs. It is very bad to program the old road to program according to the process. I thought about this problem for a long time, and finally realized that this is actually a very classic problem: object and relationship mapping problem. In fact, since OOP programming, there is this problem, so some people have filed a relational database to redesign, switch to the object database, but in fact, the relational database is not eliminated, so it can only find a solution in the upper layer application layer. Program. At this time, I understand that what I need is actually an ORM product. The ORM I thought in was JDO, so I downloaded two JDO products, prepared to study hard, but after a period of time, I found that I was very disappointed with JDO, the reasons are as follows: 1, JDO does not have a good open source Free realization, good products are commercial products and have no sales and technical support in China. This caused JDO only to learn, it could not be used in the actual project, otherwise, when you sell the software to the customer, you have to tell him, you have to buy an abroad product product, and There is no technical support in China. If you have a long-lasting layer, we can't solve it. Please make an international long distance to solve the problem. Do you think customers can promise? 2, JDO is not a lightweight package, it tries to establish a complete persistent layer frame, but it is still very imperfect, causing JDO feeling more cumbersome, many ways to make people feel cumbersome and weird. This has increased the burden of programmer learning and programming, and the package will cause a serious problem to make an error message, it is very difficult to debug, you are difficult to accurately position the error, the smoother, the smoother, The easier if the problem is, the more easily solve, the heavier the package, the more complicated the problem, the more you can't find the reason, the CMP is a good example, the error, the error, the debugging is very difficult and trouble. 3, JDO standard is very imperfect, there is a major defect.

The most important problem is reflected in the PO. It does not exist from PM (equivalent to Hibernate's session). This is a very serious problem that will cause a lot of VO to make a lot of VO when making programming, and it is static. Pojo's Enhancer, can not run the Dynamic enhance, unable to perform incremental compilation and debugging, programming, and debugging, it is very cumbersome, each time you have a total of a tool to enhance for Pojo; there are some defects, such as JDOQL is not perfect, The expression of mapping relationship is not strong enough. 4, the split of JDO products. This problem is also more serious, due to the defects of JDO1.0 standards, and JDO2.0 standard is still out of date, and each JDO manufacturer is able to stand out in the competition, in addition to improving the operation and performance, Attracting customers, you must have your own product characteristics. So 1.0 standard defects just give the stage where they play, each manufacturer will have its own unique solution to solve the standard defect, but this has caused JDO products in fact split. What exempted this split is? I can make an example: you write good Pojo, using a JDO Enhancer to enhance gets the PO, running on another JDO product. This is very similar to the split of UNIX, the result is the incompatibility of binary code level, but can only be compatible with C source code levels. The current JDO has this trend, just like the difference in App Server, a developed EJB on WebLogic, transplanted to WebSphere, you must re-configure it. The ORM in my mind has the following characteristics: 1. Open source and free license, I can study the source code, rewrite the source code, and perform custom customization when needed. 2, lightweight package, avoid introducing too much complex problems, easy to debug, and also reduce the burden of programmers. 3, with scalability, Open, when it is not enough, you can expand your own code. 4. Developers are active, and the product has a stable development guarantee. After abandoning JDO, I used to eliminate Toplink, Cocobase, Castor, etc. according to the principles above, and finally selected Apache Ojb and Hibernate. OJB exclusion is easy to make, one because its document is too simple, too small; second, because the OJB plan has fully supported JDO, its API will have major changes, so at this stage study OJB is an error, wait for it The API is stable after it is not too late. Hibernate discovery is a very casual thing, just in the product of JDO, it comes with it, but when I started studying Hibernate, I found that I finally found the ORM I dreamed of. Hibernate is completely in line with the standards mentioned above, but also solves all of the shortcomings of JDO, and the improvement of the way. Hibernate's document is also very very distinctive, it is not only the function of Hibernate, it is actually a summary of the best practices for lasting layer design, examples inside the document, and the summary of the document is all Optimal design crystallization. I seriously read the feeling of Hibernate, not only to hold Hibernate, and the experience of the designed designed design has grown a large piece, and it has never been a lot of learning in the design of the lasting layer. This also felt that Gavin is definitely a big cattle.

Of course, Hibernate is the most reused reason is that hibernate is a software I have finished. Hibernate's source code is very small, and it is very concise, I always feel quite strange, so few source code can achieve so much function, it is a miracle. Hibernate's source code is very clear and simple. The source code is easy to read. Once I encounter problems not talking to the document, or when I mention it, I can't figure it out, I will go to the source code. All the questions are suddenly turned out, and I will make me specially clearly for Hibernate's operational principles and details. It seems to know like the code you wrote. I know clearly, how to write the program to make Hibernate's efficiency, the most survival The program has a mistake, and it is clear that what is the problem, how to solve it. So use hibernate to make me especially rest assured, I can control it, not as too complicated software, your own framework is very complicated, plus no sources, I don't know what is going on. -------------------------------------------------- ---------- One, Hibernate is a lightweight object package for JDBC, which is a separate object persistent layer frame, and App Server, and EJB has no inevitable connection. Hibernate can be used in any case where any JDBC can be used, such as the database access code of the Java application, and the implementation class of the DAO interface, can even be the code of accessing the database inside BMP. In this sense, Hibernate and EB are not something in a category, nor does it exist. Second, hibernate is a framework closely associated with JDBC, so Hibernate's compatibility and JDBC driver, and databases have a certain relationship, but use its Java program, and APP Server does not have any relationship, and there is no compatibility problem. . Third, Hibernate can't be used to compare directly with Entity Beans, only in the framework of the J2EE project can be compared. And even if it is placed in the software overall frame, Hibernate is also an alternative to JDBC, rather than the alternatives of entity beans, let me listen to the frame structure of N times, I have listed N times: Traditional architecture : 1) Session bean <-> DB In order to solve the alternative architecture of performance barriers: 2) Session bean <-> DAO <-> JDBC <-> DB Using Hibernate to improve the development efficiency of the above architecture: 3) Session bean <-> DAO <-> Hibernate <-> DB is analyzed above 3 architectures: 1, memory consumption: Architecture 2 using JDBC 2 is undoubtedly the most survival, Hibernate architecture 3 times, EB Architecture 1 is the worst. 2, running efficiency: If the JDBC code is written very optimized, the JDBC architecture has the highest efficiency, but in the actual project, this is almost can't do. This requires the programmer very proficient in JDBC, use the BATCH statement, adjust the preapredstatement Batch size And the parameters such as FETCH Size, as well as the result set cache, etc. In general, the programmer can't do this. Therefore, the Hibernate architecture exhibits the fastest running efficiency. The architectural efficiency of EB is very far.

转载请注明原文地址:https://www.9cbs.com/read-33027.html

New Post(0)