Hibernate interview questions

Source: Internet
Author: User

1. What is Orm?
A: object-relational-mapping (ORM) is a technology designed to solve the mismatch between object-oriented and relational databases. To put it simply, Orm automatically persists the objects in Java programs to relational databases by using metadata that describes the ing between objects and databases, in essence, data is converted from one form to another.

2. What are the five core interfaces of hibernate?
A: The five core interfaces of hibernate include:
(1) configuration interface: Configure Hibernate and start hibernate to create the sessionfactory object.
(2) sessionfactory interface: initializes Hibernate and acts as a proxy for the data storage source to create a session object. sessionfactory is thread-safe, this means that the same instance can be shared by multiple threads of the application. It is a heavyweight level-2 cache.
(3) Session interface: stores, updates, deletes, loads, and queries objects. The thread is insecure. It is lightweight to avoid multiple threads sharing the same session, level 1 cache.
(4) Transaction interface: manage transactions.
(5) query and criteria interfaces: Execute database queries.

3. What is heavyweight? What is lightweight? 
A: lightweight means that it does not need to consume too much resources to create and destroy session objects. This means that session objects can be created and destroyed frequently in programs.

Heavyweight means you cannot create or destroy its instances at will, or it will occupy a lot of resources.

4. How does hibernate handle transactions?
A: hibernate transactions are actually the underlying JDBC. The encapsulation of transaction or JTA transaction. JDBC transaction is used by default.

5. What are the transaction processing methods provided in the connection class?
A: There are three transaction processing methods in the connection class.
(1) setautocommit (Boolean autocommit) sets whether to automatically submit a transaction. By default, the transaction is automatically committed, that is, true. It is disabled by setting false.
(2) Commit () commits a transaction.
(3) rollback () rolls back the transaction.

6. What data query methods does hibernate provide?
A: There are three methods for hibernate to query data: hql, QBC, and SQL.

7. What is JDO?
A: JDO is a new specification for Java object persistence. It is short for Java data object and is also a standardized API for accessing objects in a data warehouse. JDO provides transparent object storage. Therefore, for developers, no additional code (such as the use of JDBC APIs) is required to store data objects ). These tedious routine work has been transferred to the JDO product provider, freeing developers to concentrate their time and effort on business logic. In addition, JDO is flexible because it can run on any data underlying layer. JDBC is more common to Relational Database Service (RDBMS) JDO and provides underlying storage functions for any data, such as relational databases, files, XML, and object databases (odbms, makes applications more portable.

8. What is the working mechanism of the data connection pool?
A: When the server is started, a certain number of pool connections will be established, and a large number of pool connections will be maintained. When the client program needs to connect, the pool driver returns an unused pool connection and logs its table as busy. If no idle connection exists, the pool driver creates a certain number of connections. The number of new connections is determined by the configuration parameters. When the pool connection call is completed, the pool driver records the connection table as idle, and other calls can use the connection.

9. What is the difference between update () and saveorupdate () in hibernate?
A: The saveorupdate () method can implement the update () function, but more steps are required. The specific steps are as follows: if the object has been persisted in this session, no operation is performed; the identifier property of an object does not exist in the database or is a temporary value. Call the SAVE () method to save it. If another object in the session has the same identifier, an exception is thrown. If none of the preceding conditions are met, update () is called for update.

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.