In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Network Security >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly explains "how to operate Hibernate". Friends who are interested may wish to have a look. The method introduced in this paper is simple, fast and practical. Now let the editor take you to learn how to operate Hibernate!
First, use Hibernate API
Create a tool class management session factory
It should be noted here:
(1) SessionFactory does not need to be created repeatedly
(2) if you start a session with openSession (), you need to close it.
Second, use Hibernate to query, modify and delete operations.
1. Use Hibernate to query data
Load an instance of the specified type through the primary key value
2. Use Hibernate to modify and delete the department
Modify the department
Delete a department
3. Code demonstration:
3. Three states of Java objects in Hibernate
The transition between three states
Fourth, refresh cache mechanism
1. When caching (calling the flush () method of Session), Hiberante detects the object in the persistent state in Session to determine whether the object's data has changed
2. To refresh the cache is to synchronize the database with the Session cache.
3. A dirty check is performed when the cache is flushed
4.Session flushes the cache at the following points in time
Call the flush () method of Session
Call the commit () method of Transaction
The 5.commit () method flushes the cache first.
Fifth, summarize the use of Hiberante API methods
VI. Hiberante Association Mapping
1. The most common relationship between classes is association.
One-way association
Two-way association
2. Many-to-one relationship
Configure a many-to-one association from Emp to Dept
(1) Emp persistence class
(2) Emp.hbm.xml
3. One-to-many relationship
Configure one-to-many associations from Dept to Emp
(1) Dept persistence class
(2) Dept.hbm.xml
4. Many-to-many relationship
Configure bidirectional many-to-many associations for Project and Employee
(1) Project and Employee persistence classes
(2) Project.hbm.xml, Employee.hbm.xml
At this point, I believe you have a deeper understanding of "how to operate Hibernate", might as well come to the actual operation of it! Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.