官术网_书友最值得收藏!

Introduction

In this chapter, we will take a look at how the hibernate and ORM (Object-relational Mapping) frameworks work, how to configure hibernate in different ways, and the libraries that are required for the hibernate application. An essential part of the application is the hibernate configuration. Through the configuration, we can provide database information to the hibernate engine, such as the database host, port, username, password, the database name, the drive class, and so on.

In the older era of Java development, developers used some methodologies to persist data. To persist data means to save or store data in some storage medium by maintaining it in a certain state. Once the data is successfully persisted, it can be used at any given time. A database is the more preferable storage medium for a transactional operation. Usually, we use JDBC (Java Database Connectivity) to perform such operation with the database.

If we use the JDBC operation, we need to work a bit harder and take care of the following processes:

  • Opening a database connection
  • Maintaining an open connection
  • Building a query
  • Executing a query
  • Getting a response to the query
  • Mapping the query response with the custom classes
  • Closing the database connection

To avoid this hectic process, we can use the ORM tools available in the market. ORM stands for Object Relation Mapping. It works as a bridge between the application and database by simplifying the communication between them.

The benefits of the ORM framework are as follows:

  • It reduces the development time/cost.
  • It speeds up the development.
  • It provides us with portability. Hibernate supports multiple databases, so there is no need to write a database-specific code.

This is a useful feature of hibernate. Generally, all databases have their own syntax made up of Data Definition Language (DDL) or Data Manipulation Language (DML) statements. If we used JDBC, we would need to write a database-specific code as our database is changed. However, hibernate gets rid of the developer's headache by handling this issue.

The syntax of a query may be different for different database parameters; still, hibernate works in the same way for all types of databases. Hibernate's term dialect helps achieve this type of functionality. The implementation of the dialect class is provided by the database provider to inform hibernate about the syntax of this particular database.

Some useful features of hibernate are as follows:

  • Code reusability
  • Transaction management
  • Efficient collection/custom classes mapping
  • The caching mechanism supported by hibernate
主站蜘蛛池模板: 怀柔区| 屏边| 尉犁县| 宝清县| 东平县| 台州市| 淮滨县| 修水县| 齐河县| 永兴县| 彭州市| 怀集县| 富阳市| 北辰区| 综艺| 高碑店市| 巍山| 苍溪县| 商水县| 专栏| 饶河县| 博湖县| 广饶县| 黔南| 衡东县| 永年县| 开封市| 玛沁县| 上饶市| 屏东市| 肥城市| 台南市| 中超| 奉贤区| 卢氏县| 贵州省| 新密市| 惠东县| 台中市| 达拉特旗| 沂南县|