Hibernate is an object-relational mapping (ORM) framework that sits on top of JDBC. You work with entities and queries in Java, and Hibernate generates SQL and executes it through JDBC drivers, connections and prepared statements behind the scenes. JDBC is the low-level standard API for talking to relational databases; Hibernate is a higher-level layer that uses it.
Hibernate is also the most widely used implementation of Jakarta Persistence (JPA), the standard ORM specification, so most applications use Hibernate through the JPA API.
Every Hibernate operation ends in JDBC calls. When you persist an entity, Hibernate builds an INSERT, obtains a Connection from a connection pool, creates a PreparedStatement, binds parameters and executes it. Reading results works the same way in reverse: a ResultSet is converted into entity objects.
| Layer | Responsibility |
|---|---|
| Your code | Entities, repositories, EntityManager or Session |
| Jakarta Persistence / Hibernate ORM | Mapping, caching, dirty checking, SQL generation, transactions |
| JDBC | Connections, statements, result sets, driver protocol |
| Database driver and database | Executes SQL |
Hibernate needs a JDBC driver on the classpath and a JDBC URL in its configuration, which shows the dependency directly:
In current Hibernate versions the dialect is usually detected automatically from the JDBC metadata, so setting it is optional.
With JDBC you write SQL, manage resources and map rows to objects by hand.
Always use try-with-resources so connections are returned, and always use prepared statements with parameters to prevent SQL injection.
With Hibernate you declare a mapping once and let the framework do the rest.
Note the package is jakarta.persistence from Jakarta EE 9 and Hibernate 6 onward; older code used javax.persistence. Hibernate generates the SQL, tracks changed fields, and flushes them in the transaction.
@OneToMany, @ManyToOne) without manual ResultSet code.Hibernate is productive for domain-heavy CRUD applications, but the abstraction has costs: the N+1 select problem with lazy associations, surprising flushes, and a learning curve around sessions and entity states. Turn on SQL logging and use fetch joins or entity graphs to control queries.
Plain JDBC, or a thin helper such as Spring's JdbcClient, jOOQ or MyBatis, fits reporting queries, bulk operations, and cases where you want full control of the SQL. Many applications combine both: Hibernate for the domain model, JDBC or native queries for heavy reports. Hibernate also exposes the underlying connection through session.doWork(connection -> ...).
No. Hibernate depends on JDBC and calls it internally. It removes the need to write JDBC code yourself, but a JDBC driver is still required.
JPA (now Jakarta Persistence) is a specification, and Hibernate is an implementation of it, with extra features of its own. Writing to the JPA API keeps you portable.
It adds some overhead for mapping and caching, but well-tuned Hibernate is fast enough for most applications. Performance problems usually come from inefficient queries, not from Hibernate itself.
Yes. Use native queries or Session.doWork for custom SQL while Hibernate manages the same transaction and connection.
Hibernate is an ORM built on JDBC: JDBC moves SQL and rows to and from the database, and Hibernate maps those rows to Java objects and generates the SQL for you. Choose Hibernate or JPA for object-centric applications, and JDBC-style tools where you need exact SQL control.