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

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
主站蜘蛛池模板: 湖南省| 扬州市| 定安县| 新民市| 抚远县| 二手房| 盐池县| 合水县| 岳池县| 临朐县| 克什克腾旗| 朔州市| 合江县| 天台县| 刚察县| 石城县| 屏山县| 澜沧| 五大连池市| 宁强县| 循化| 金沙县| 老河口市| 陇西县| 额济纳旗| 密山市| 绍兴市| 南雄市| 吉木乃县| 镇江市| 磴口县| 乐安县| 南部县| 东兴市| 屯昌县| 突泉县| 舒城县| 德清县| 奇台县| 永福县| 永济市|