Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the basics of Hibernate

2025-01-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly explains "what are the basic knowledge of Hibernate". The explanation content in this article is simple and clear, easy to learn and understand. Please follow the ideas of Xiaobian slowly and deeply to study and learn "what are the basic knowledge of Hibernate" together!

Hibernate is an upgraded version of JDBC, dedicated to connection databases.

Hibernate is simpler to use than JDBC and does not require a lot of input to connect to database code. Extract database data without loop extraction. The method of use is:

1. Create a Java Common Project

2. Create user library Add jar package in three places: two Hibernate and one MYSQL driver

3. Create Hibernate configuration file, Hibernate.cfg.xml

4. Create entity class user

5. Find eg to the bottom of Hibernate file to find user.hbm.xml mapping file, copy to the mapping file

6. Add the mapping file user.hbm.xml section to Hibernate.cfg.xml

7. Create a database and import entity mappings into the database using Hibernate

According to the primary key Id to get a persistent object, Hibernate has two methods, a get, a load, their two parameters are the same, both return an Object

Their differences: Execute the get method to generate query sql immediately to query the database to get the corresponding pojo. If there is no corresponding record in the database, it returns null. Execute the load method. SQL statement will not be generated immediately. Instead, query the database when the returned object is used. That is, the load method has default delayed loading. After executing the load method, it returns not a pojo object, but a proxy of the pojo object.(It is said that Hibernate is a proxy way to achieve delayed loading, this is still confused), if there is no corresponding record in the database, the load method will throw an exception ObjectNotFoundException Look at the DAO class we generated through the database with MyEclipse Hibernate tool, its findById method is session.get () method, this is to get pojo objects immediately, if it is load method, if the session is closed after the load is executed, Then I'm afraid the next time I use this pojo object, I'll report a session closed error.

There is also the second parameter id of these two methods, which must implement the java.io.Serializable interface, that is, serializable.

Thank you for reading, the above is "Hibernate basics what" content, after the study of this article, I believe that we have a deeper understanding of Hibernate basics what this problem, the specific use of the situation also needs to be verified. Here is, Xiaobian will push more articles related to knowledge points for everyone, welcome to pay attention!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report