In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
Editor to share with you what are the core interfaces in Hibernate, I believe most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!
It includes seven core interfaces: Session interface, SessionFactory interface, Configuration interface, Transaction interface, Query and Criteria interface, Callback interface and policy interface.
1.Session interface
The Session interface is one of the most important interfaces for Hibernate developers. However, in Hibernate, the instance
The transformed Session is a lightweight class, and it doesn't take a lot of resources to create and destroy it. This is really important in practical projects.
Because in the client program, Session objects may be created and destroyed constantly, if the cost of Session is too high, it will be tied to
Unification brings bad effects. But it's worth noting that the Session object is not thread-safe, so in your design, * * is a
The thread creates only one Session object.
In the minds of the designers of Hibernate, they see session as an intermediate interface between data connection and transaction management.
We can think of session as a buffer of persistent objects. Hibernate can detect changes to these persistent objects, and
Refresh the database when the. We sometimes call Session a persistence layer manager because it contains these persistence layer related operations
Such as storing persistent objects to the database and obtaining them from the database. Please note that the session of Hibernate is different from JSP
HttpSession in application. When we use the term session, we refer to session in Hibernate, while
We will later call the HttpSesion object the user session.
2. SessionFactory interface
A design pattern, the factory pattern, is used here, and the user program obtains the Session's from the factory class SessionFactory
An example.
What makes you feel strange is that SessionFactory is not lightweight! In fact, the intention of its designer is to make it work in the whole
Share in the application. Typically, a project usually requires only one SessionFactory, but when your project needs to fuck
When making multiple databases, you must specify a SessionFactory for each database.
SessionFactory actually acts as a buffer in Hibernate, buffering the SQL automatically generated by Hibernate.
Statements and some other mapping data, and buffers some data that may be reused in the future.
3.Configuration interface
The purpose of the Configuration interface is to configure Hibernate and start it. At the startup of Hibernate
In the process, an instance of the Configuration class first locates the location of the mapping document, reads these configurations, and then creates a
SessionFactory object.
Although the Configuration interface plays only a small role in the entire Hibernate project, it starts the
Every object you meet when you hibernate.
4.Transaction interface
The Transaction interface is an optional API. You can choose not to use this interface and replace it with Hibernate.
The underlying transaction code written by the designer himself. The Transaction interface is an abstraction of the actual transaction implementation, these implementation packages
This includes JDBC transactions, UserTransaction in JTA, and even CORBA transactions. The reason for this design is to get out of the way.
The issuer can use a unified transaction interface so that his project can easily move values between different environments and containers.
5.Query and Criteria interface
The Query interface allows you to easily query databases and persistent objects, which can be expressed in two ways: HQL language or text
The SQL statement of the local database. Query is often used to bind query parameters, limit the number of query records, and finally perform query operations.
The Criteria interface is very similar to the Query interface in that it allows you to create and execute standardized object-oriented queries.
It is worth noting that the Query interface is also lightweight and cannot be used outside of Session.
6. Callback interface
When some useful events occur, such as the loading, storage, and deletion of persistent objects, the Callback interface notifies
Hibernate goes to receive a notification message. Generally speaking, the Callback interface is not necessary in user programs, but you should
You may use it when you create an audit log in your project.
7. Policy interface
Hibernate differs from some other open source software in that it is highly extensible through its built-in policy mechanism
To make it happen. When you feel that some of the functions of Hibernate are inadequate, or there are some defects, you can develop your own strategy to replace it, and all you have to do is inherit one of its policy interfaces, and then implement your new strategy, as follows
Its policy interface:
Generation of ◆ primary key (IdentifierGenerator interface)
◆ native SQL language support (Dialect abstract classes)
◆ buffering mechanism (Cache and CacheProvider interfaces)
◆ JDBC connection Management (ConnectionProvider Interface)
◆ transaction management (TransactionFactory, Transaction, and TransactionManagerLookup interfaces)
◆ ORM Policy (ClassPersister interface)
◆ attribute access Policy (PropertyAccessor Interface)
Creation of ◆ proxy object (ProxyFactory interface)
Hibernate creates a default implementation for each of the mechanisms listed above, so if you just want to enhance one of its strategies
Simply inherit the class, and there is no need to write code from scratch.
These are all the contents of the article "what are the core interfaces in Hibernate". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
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.