JDBC vs Hibernate

JDBC stands for Java Database Connectivity which allows developers to connect, query and update a database using the Structured Query Language(SQL).

Hibernate is an Object-Relational Mapping (ORM) solution for JAVA.
It is a powerful, high performance ORM framework.

Listed below is the difference beetween JDBC and Hibernate


If we use JDBC in our application, then we need to write SQL queries
to persist the object data in the database tables, so here we have to map
each column with corresponding attribute of an object very carefully in the

In JDBC, java code is heavily dependent on database table, so any
change in the table or column requires changing lot of code including the
object and the SQL query.

With JDBC, when we get the result set from the DB,we will get it in
the form of rows in table, so we need to process the result set manually to
populate its data to the java object.

JDBC supports only native SQL query, so some database management
system may not understand these queries until we change it according to those
database’s required syntax.

In any application, it is very good to maintain the cache to improve
the performance but JDBC does not come with Cache, we need to manually write
a cache management code.


If we use Hibernate in our application,then we are not required to
write SQL queries to persist the object in database tables, instead we need
to write one time mapping file and we can directly save the object.

In Hibernate,Object and table mapping is done in the Mapping xml
file, so any change in the table or column requires us to change only in the
mapping xml file.

In Hibernate, since there is already a mapping between object and table
, when we retrieve data from DB, we will get the java object itself.

It reduces the developers time and effort.

Hibernate provides more powerful query language called HQL(Hibernate
query language) which is independent underlying database, through HQL we can
write more efficient queries and its syntax is very similar to SQL. Hibernate
also allows us to use native SQL queries in case if we have already written
more SQL queries and we don’t want to convert them into HQL.

Hibernate has come with Caching mechanism, and with different types
of cache can be enabled so that retrieved data from DB will be moved to cache
and can be retrieved from there.

About the Author

Karibasappa G C (KB)
Founder of javainsimpleway.com
I love Java and open source technologies and very much passionate about software development.
I like to share my knowledge with others especially on technology 🙂
I have given all the examples as simple as possible to understand for the beginners.
All the code posted on my blog is developed,compiled and tested in my development environment.
If you find any mistakes or bugs, Please drop an email to kb.knowledge.sharing@gmail.com

Connect with me on Facebook for more updates

Share this article on