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

How to operate API with Hibernate

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

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

This article introduces Hibernate how to use API, the content is very detailed, interested friends can use for reference, I hope it can be helpful to you.

Configuration object

Function: configuration loading class, used to load the main configuration, ormmetadata loading.

/ / 1 create, call empty parameter construction

Configuration conf = new Configuration ()

/ / 2 read the specified configuration file = > empty load method, and load the hibernate.cfg.xml file under src

Conf.configure ()

/ / 3 create a SessionFactory object based on configuration information

SessionFactory sf = conf.buildSessionFactory ()

/ / 4 get the session object

Session session = sf.openSession ()

/ / Open the thing and get the tx object of the transaction

Transaction tx = session.beginTransaction ()

Tx.commit ()

Tx.rollback ()

Session.close ()

Sf.close ()

/ / get a session object bound to the thread

Sf.getCurrentSession ()

SessionFactory object

Function: used to create a factory that manipulates session objects, the core object of the database.

Note: 1.sessionfactory is responsible for saving and using all configuration information. The consumption of memory resources is very large.

2.sessionFactory is a thread-safe object design.

Conclusion: only one sessionFactory object can be created in a project

Session object

Function: express the connection (session) between hibernate framework and database. Session is similar to connection object in JDBC era. You can also add, delete, modify and query the data in the database. Session is the core object of Hibernate operating database.

On how to use Hibernate API to share here, I hope that the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.

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

Internet Technology

Wechat

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

12
Report