JDBC vs
HIBERNATE
•Yastee A. Shah (16it148)
By:
Introduction to Hibernate
Introduction to
JDBC
Hibernate vs
JDBC
Fundamentally, the JDBC vs. Hibernate battle begins with deciding
between Hibernates ORM and JDBC’s SQL approach.
Reasons to consider Hibernate over JDBC
One of the main reasons developers love Hibernate is that it is a Java standard.
It is a JavaEE standard implementation which makes development much easier
as guidelines are clear for all to follow.
SOLVES OBJECT-RELATIONAL IMPEDANCE MISMATCH PROBLEMS
• When a relational database is written in an object-oriented programming
language, the issues can arise.
• Differences in data types, structural and integrity differences, manipulative and
transactional differences, can all cause object-relational impedance mismatches.
AUTOMATIC OBJECT MAPPING
• Hibernate facilitates automatic object mapping ie map database tables to
application objects during interaction with RDBMS.
• JDBC requires programmers to manually write lines of code to deal with this
problem.
Reasons to consider Hibernate over JDBC
HIBERNATE QUERY LANGUAGE (HQL)
• JDBC only supports SQL while Hibernate also supports the HQL as well as Native
SQL.
• HQL is similar to SQL in that it is an object-oriented query language. However, it
doesn’t operate on tables like SQL but rather uses persistent objects and their
properties.
• In order to bridge the gap, HQL translates queries into SQL queries that can then
initiate actions in the database.
• Native SQL allows applications to use SQL statements with Hibernate meaning
developers can choose between the two.
Reasons to consider Hibernate over JDBC
•HQL is a combination of OOPs and RDBMS concept.
SQL is entirely relational database model based.
•HQL deals with objects and their properties.
SQL operates on table data and the relationship between
different tables.
The fact that Hibernate can operate using either SQL or HQL
makes the better choice for most developers as it allows for
more flexibility.
Reasons to consider Hibernate over JDBC
DATABASE INDEPENDENCE
Since Hibernate allows for mapping between data tables and applications to be made
through XML files, this makes it easy to migrate data to a new database if required.
HIBERNATE VS. JDBC PERFORMANCE
• While the process of accessing database information is vital. Equally important is how
data is retained for repeated use.
• Caching is a key component of database performance as it helps applications reduce
the time and resources spent on disk access.Hibernate’s cache processes are set to
the application workspace.
After a query is made, relational tuples are moved to the cache to improve
performance should the data be required for repeated use. This process, when coupled
with Hibernate’s Automatic Object Mapping, makes life much easier for developers as
well as increasing performance.
• JDBC contains no caching mechanism. This needs to be coded separately.
Reasons to consider Hibernate over JDBC
LESS NEED TO REPEAT CODE
Hibernate reduces the amount of repeated lines of code required when
compared to JDBC. When inserting a record, for example, JDBC will
require a programmer to write a statement for each column of a table. This
can be quite labour intensive if the application is working with a large
number of columns.
Hibernate, on the other hand, only requires an object to be saved with
“persist(Object);” and doesn’t require any additional parameters.
SCALABILITY
Hibernate offers a good degree of scalability in any environment. This
means that it can be used for all sizes of projects from a small scale app to
one that is used by millions. Sadly, JDBC does not offer great scalability.
Reasons to consider Hibernate over JDBC
AUTOMATIC VERSIONING
Database versioning is another really important tool that helps prevent changes being accidentally rolled back by
other users. Hibernate allows for the recording of version types within an application. Whenever data is updated or
stored, a version type and time-stamp will be recorded along with the data.
This helps prevent data overwrites from occurring as in the case when two users are trying to modify the same
data set at the same time.
In this scenario, when the first user saves their changes, Hibernate will update the version field so that the second
user will be prevented from saving their changes and in effect wipe the changes made by the first user.
JDBC is not able to perform such check. This must again be coded by the developer.
COSTS
Hibernate is open source and therefore is free for anyone to use. This benefits everyone from developers to large
software development companies who don’t need to pay licensing fees.
JDBC requires developers to manually solve a lot of the tasks that Hibernate does automatically. One such
example is JDBC requires developers to take care of mapping between Java objects and database tables while
Hibernate uses object-table mapping to automate the process.
Coding a solution to this problem takes developers lots of time and effort. This in turn increases app development
time as well as raises costs. It is for this reason that Hibernate can be said to be the most cost-effective solution.
Reasons to consider Hibernate over JDBC
EASY TO LEARN
The most obvious advantage of JDBC over Hibernate is that it is much easier to learn to use. Having to spend
the time learning how different software platforms function can be a real nightmare for programmers.
If a developer doesn’t understand Hibernate’s internal workings and database design then they are not going
to be able to write good code.
A SIMPLER SOLUTION
Many developers consider Hibernate better suited for more complex applications. If an application is only going
to use a straightforward database that won’t need to be migrated, then JDBC is considered the better option.
Likewise, if the application only requires data to be stored in database tables and doesn’t require objects to be
mapped to two or more table versions, then JDBC is considered to be much better to use.
So in a nutshell, if the application database requirements are straightforward then JDBC is the better choice.
Reasons to consider JDBC over Hibernate
FASTER DEVELOPMENT PERFORMANCE AND TESTS
For hibernate, as it loads up, pre-caching means that it takes roughly 10 to 15 seconds for a small sized application to
load. Mapping to and from Object-to-tables also takes some time.
While this is not exactly a vast amount of time, it can add up for sophisticated projects and more than anything be
frustrating. JDBC doesn’t suffer from the same lag when it comes to startup and provided tables are SQL based, is
able to access/record data quickly.
JDBC supports some types of queries Hibernate does not.
JDBC is able to insert multiple objects (persistent data) at one into the same table as part of one single query. If a
developer using Hibernate wants to incorporate this function into their application, they must code it separately.
GREAT SUPPORT
Last but not least is technical support. JDBC is developed under the wing of the Oracle Corporation. This means that
developers are able to access dedicated customer services teams who are able to help them with any query that they
may have.
This support also means that there is a lot of literature online for those who need it. While it is possible for
programmers to get information on Hibernate issues, they more than likely will have to post questions to a forum and
wait for a reply.
Reasons to consider JDBC over Hibernate
The Final Thought
Thank you..!

jdbc vs hibernate.pptx

  • 1.
  • 2.
  • 3.
  • 4.
    Hibernate vs JDBC Fundamentally, theJDBC vs. Hibernate battle begins with deciding between Hibernates ORM and JDBC’s SQL approach. Reasons to consider Hibernate over JDBC One of the main reasons developers love Hibernate is that it is a Java standard. It is a JavaEE standard implementation which makes development much easier as guidelines are clear for all to follow.
  • 5.
    SOLVES OBJECT-RELATIONAL IMPEDANCEMISMATCH PROBLEMS • When a relational database is written in an object-oriented programming language, the issues can arise. • Differences in data types, structural and integrity differences, manipulative and transactional differences, can all cause object-relational impedance mismatches. AUTOMATIC OBJECT MAPPING • Hibernate facilitates automatic object mapping ie map database tables to application objects during interaction with RDBMS. • JDBC requires programmers to manually write lines of code to deal with this problem. Reasons to consider Hibernate over JDBC
  • 6.
    HIBERNATE QUERY LANGUAGE(HQL) • JDBC only supports SQL while Hibernate also supports the HQL as well as Native SQL. • HQL is similar to SQL in that it is an object-oriented query language. However, it doesn’t operate on tables like SQL but rather uses persistent objects and their properties. • In order to bridge the gap, HQL translates queries into SQL queries that can then initiate actions in the database. • Native SQL allows applications to use SQL statements with Hibernate meaning developers can choose between the two. Reasons to consider Hibernate over JDBC
  • 7.
    •HQL is acombination of OOPs and RDBMS concept. SQL is entirely relational database model based. •HQL deals with objects and their properties. SQL operates on table data and the relationship between different tables. The fact that Hibernate can operate using either SQL or HQL makes the better choice for most developers as it allows for more flexibility. Reasons to consider Hibernate over JDBC
  • 8.
    DATABASE INDEPENDENCE Since Hibernateallows for mapping between data tables and applications to be made through XML files, this makes it easy to migrate data to a new database if required. HIBERNATE VS. JDBC PERFORMANCE • While the process of accessing database information is vital. Equally important is how data is retained for repeated use. • Caching is a key component of database performance as it helps applications reduce the time and resources spent on disk access.Hibernate’s cache processes are set to the application workspace. After a query is made, relational tuples are moved to the cache to improve performance should the data be required for repeated use. This process, when coupled with Hibernate’s Automatic Object Mapping, makes life much easier for developers as well as increasing performance. • JDBC contains no caching mechanism. This needs to be coded separately. Reasons to consider Hibernate over JDBC
  • 9.
    LESS NEED TOREPEAT CODE Hibernate reduces the amount of repeated lines of code required when compared to JDBC. When inserting a record, for example, JDBC will require a programmer to write a statement for each column of a table. This can be quite labour intensive if the application is working with a large number of columns. Hibernate, on the other hand, only requires an object to be saved with “persist(Object);” and doesn’t require any additional parameters. SCALABILITY Hibernate offers a good degree of scalability in any environment. This means that it can be used for all sizes of projects from a small scale app to one that is used by millions. Sadly, JDBC does not offer great scalability. Reasons to consider Hibernate over JDBC
  • 10.
    AUTOMATIC VERSIONING Database versioningis another really important tool that helps prevent changes being accidentally rolled back by other users. Hibernate allows for the recording of version types within an application. Whenever data is updated or stored, a version type and time-stamp will be recorded along with the data. This helps prevent data overwrites from occurring as in the case when two users are trying to modify the same data set at the same time. In this scenario, when the first user saves their changes, Hibernate will update the version field so that the second user will be prevented from saving their changes and in effect wipe the changes made by the first user. JDBC is not able to perform such check. This must again be coded by the developer. COSTS Hibernate is open source and therefore is free for anyone to use. This benefits everyone from developers to large software development companies who don’t need to pay licensing fees. JDBC requires developers to manually solve a lot of the tasks that Hibernate does automatically. One such example is JDBC requires developers to take care of mapping between Java objects and database tables while Hibernate uses object-table mapping to automate the process. Coding a solution to this problem takes developers lots of time and effort. This in turn increases app development time as well as raises costs. It is for this reason that Hibernate can be said to be the most cost-effective solution. Reasons to consider Hibernate over JDBC
  • 11.
    EASY TO LEARN Themost obvious advantage of JDBC over Hibernate is that it is much easier to learn to use. Having to spend the time learning how different software platforms function can be a real nightmare for programmers. If a developer doesn’t understand Hibernate’s internal workings and database design then they are not going to be able to write good code. A SIMPLER SOLUTION Many developers consider Hibernate better suited for more complex applications. If an application is only going to use a straightforward database that won’t need to be migrated, then JDBC is considered the better option. Likewise, if the application only requires data to be stored in database tables and doesn’t require objects to be mapped to two or more table versions, then JDBC is considered to be much better to use. So in a nutshell, if the application database requirements are straightforward then JDBC is the better choice. Reasons to consider JDBC over Hibernate
  • 12.
    FASTER DEVELOPMENT PERFORMANCEAND TESTS For hibernate, as it loads up, pre-caching means that it takes roughly 10 to 15 seconds for a small sized application to load. Mapping to and from Object-to-tables also takes some time. While this is not exactly a vast amount of time, it can add up for sophisticated projects and more than anything be frustrating. JDBC doesn’t suffer from the same lag when it comes to startup and provided tables are SQL based, is able to access/record data quickly. JDBC supports some types of queries Hibernate does not. JDBC is able to insert multiple objects (persistent data) at one into the same table as part of one single query. If a developer using Hibernate wants to incorporate this function into their application, they must code it separately. GREAT SUPPORT Last but not least is technical support. JDBC is developed under the wing of the Oracle Corporation. This means that developers are able to access dedicated customer services teams who are able to help them with any query that they may have. This support also means that there is a lot of literature online for those who need it. While it is possible for programmers to get information on Hibernate issues, they more than likely will have to post questions to a forum and wait for a reply. Reasons to consider JDBC over Hibernate
  • 13.
  • 14.