Difference Between JDBC and Hibernate

Table of Contents

computerJDBC vs. Hibernate

Java Database Connectivity (also known as JDBC) is an API specifically built for the Java programming language. It defines how a client is able to access a database by providing methods for querying and updating data in a database. It is oriented more specifically towards relational databases. It was first introduced to the market as a part of the Java 2 Platform, Standard Edition, version 1.1 (or J2SE). It was bundled together with a reference implementation JDBC to ODBC bridge, enabling connections with the API to any ODBC accessible data source in the JVM host environment.

Hibernate is an object oriented mapping library (or ORM library) specifically built for the Java language. It provides a framework for mapping an object oriented domain model to a traditional relational database. It also solves object relational impedance mismatch problems –that is, problems in which a relational database management system (or RDBMS) is being used by a program written in an object oriented programming language or style. It accomplishes this by replacing direct persistence related database accesses with high level handling functions. It is free, open source software and is distributed under the GNU Lesser General Public License.

JDBC works by allowing a variety of implementations to exist and used by the same application. It provides a mechanism by which the correct Java packages are dynamically loaded and registered with the JDBC Driver Manager –which is used as a connection factory, of sorts, that creates JDBC connections. These connections support the creation and execution of statements. They may be update statements (the SQLs CREATE, INSERT, UPDATE, and DELETE, for example). They may also be query statements such as SELECT. A JDBC connection may also invoke stored procedures –that is, those procedures that are stored in the database data dictionary.

Hibernate primarily functions to map from Java classes to database tables, as well as from Java data types to SQL data types. It also provides data query and retrieval facilities. It is able to generate SQL calls, thus relieving the developer from manual result set handling and object conversion. This keeps the application portable to all SQL databases that are supported through the library. It maps Java classes to the database tables by configuring an XML file (in which Hibernate is able to generate skeletal source code for the persistence classes) or using Java Annotation (which makes the former action moot). Hibernate also supports mapping of custom value types, which makes three specific scenarios possible: overriding the default SQL type, chosen by Hibernate when mapping a column to a property; mapping Java Enum to columns as though they were regular properties; and mapping a single property to multiple columns.

Summary:

1. JDBC is an API that defines how a client can access a database; Hibernate is an ORM library that provides a framework for mapping an object oriented domain model to a traditional relational database.

2. JDBC allows various implementations to exist and by used by the same application; Hibernate maps from Java classes to database tables.


ncG1vJloZrCvp2OxqrLFnqmeppOar6bA1p6cp2aemsFwwMScn6ennKS0unvDop2fnaKau6SxjJucra%2BVmrtutsObmmaZnpl6qbXBnqmnmaSafA%3D%3D