- Java Hibernate Cookbook
- Yogesh Prajapati Vishal Ranapariya
- 409字
- 2021-07-16 19:59:45
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
- JavaScript高效圖形編程
- The Modern C++ Challenge
- MySQL 8從入門到精通(視頻教學版)
- Machine Learning with R Cookbook(Second Edition)
- Three.js開發指南:基于WebGL和HTML5在網頁上渲染3D圖形和動畫(原書第3版)
- C語言程序設計實訓教程
- Modular Programming in Java 9
- iOS編程基礎:Swift、Xcode和Cocoa入門指南
- Go語言精進之路:從新手到高手的編程思想、方法和技巧(2)
- “笨辦法”學C語言
- Learning Hadoop 2
- C語言程序設計實訓教程與水平考試指導
- SpringBoot從零開始學(視頻教學版)
- Microsoft HoloLens By Example
- 算法超簡單:趣味游戲帶你輕松入門與實踐