006 open-source o/R ing framework content review

Source: Internet
Author: User

Hibernate is an O/R ing framework (also known as ORM)

From the perspective of ORM words, O --- object (Object Model); R --- relational (association model) can map objects and associations. Of course, this is only part of the function, A perfect ORM framework should have more functions, such as query statements related to hql, and provide cache mechanisms (level-1 cache and level-2 cache ).

When developing a database in Java, JDBC is used, but a large amount of the same code needs to be written.High Production EfficiencyWhile hibernate does not allow you to write a lot of the same Code. This improves production efficiency. On the other hand, Hibernate allows usMore object-orientedDevelopment, there is also a portable hibernate only need to change the configuration file (Database adapter) options, you canVery convenient portingInstead of re-writing the JDBC and SQL statements corresponding to different database manufacturers. And hibernate.Resolve impedance mismatch(Java classes have an inheritance relationship, but relational databases do not have this function (currently, databases are not object-oriented and all are relational databases). The Hibernate framework is used,Good intrusion(So Hibernate is called a Lightweight Framework)

O/R ing framework and use environment: add in the program → modify → save; query can be batch, but the modification cannot be batch; the program has a large amount of data read-only, in this way, the data can be read to the cache at a time. There is a natural relationship between objects, and database SQL-specific statement optimization is not required.

The o/R ing framework is not suitable for environments: Clustering operations: Batch addition and modification. Batch statistics query.

Configuration object: Read the hibernate configuration file (hibernate. cfg. XML or hiberante. properties. new configuration () reads hibernate by default. properties, so use new configuration (). configure (); To Read hibernate. cfg. xml configuration file

 

Sessionfactory: a heavyweight Object. It is time-consuming to create it. Because it corresponds to all the configurations in a database, and some cache mechanisms are maintained by sessionfactory, it is bound to the second-level cache. It is generally created only once, but it is thread-safe.

 

Session: Non-thread-safe. It is created through sessionfactory. Do not allow multiple threads to access the same session at the same time. Otherwise, some unknown problems may occur. Generally, a request corresponds to a session, and the session must be closed after the request is completed.

 

Transaction: by default, Hibernate does not automatically start transactions. Therefore, you must manually start transactions, manually submit transactions, manually roll back transactions, and manually close transactions. Of course, the configuration file can be configured as automatic. Generally, it is manual.

 

The normal development idea of hibernate: Considering the object model, the object model is established, the object graph is established, the relationship between objects is established, and then the hbing file (HBM) is compiled ), then generate a database table based on the ing file. The database is transparent to me. We only operate on objects without worrying about the database.

006 open-source o/R ing framework content review

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.