JDBC, ORM/MyBatis, JPA/Hibernate
date
Aug 18, 2022
slug
jdbc-orm-mybatis-jpa-hibernate
status
Published
tags
Concept
Hibernate
JDBC
JPA
Java
Mybatis
summary
type
Post
JDBC
JDBC: Java Database Connectivity API, which is a specification for making SQL requests from Java.
Java
has a standard API for connecting to a database executing SQL
queries against it. It’s called JDBC
or Java Database Connectivity
.It’s an excellent standard, but it’s hard to develop applications rapidly with.
Living as we do in a Object-Oriented World, it’s inconvinient to have to break our objects apart and reassemble them manually.
ORM/MyBatis
ORM: Object-Relational Mapping. A general term describing a set of technology that can be used to automatically convert data between database representation and application representation.
The idea of
ORM
is that the data that can be stored in objects is ultimately the same type of data that can be stored in a database, and the conversion between the two can be automated.MyBatis: A thin ORM over JDBC that automatically generates code to execute SQL statements over JDBC and maps the results to Java objects.
MyBatis
provides a shallow ORM
layer over JDBC
(Java Database Connectivity). That means it helps map your Java
objects to queries that save and retrieve data using JDBC
.MyBatis
is a persistence framework for having SQL
support. MyBatis
couples objects with SQL
statements using an XML descriptor or annotations.MyBatis
is mostly used through interface definitions. MyBatis
automatically generates classes that implement the interface and makes them available as Spring
beans.JPA/Hibernate
Java Persistence API (JPA): A specification describing how to manage relational data.
Hibernate: An implementation of the JPA Specification.
To go into a little more detail,
JPA
describes the API for a variety of features, such as:- Data Conversion
- Querying
- Data Validatioon
- Schema Generation
While
Hibernate
implements the actual behaviors that makes these features work.So when we talk about using
Hibernate
, what we usually mean is that we’re using the specification defined by JPA
but implemented by Hibernate
.