Hibernate vs MyBatis vs JDBC:
is there a silver bullet?
Eugene Varfolomeev
Dnepropetrovsk
15 May 2014
2
What is this presentation about?
 Framework and API fundamental principles overview
 Features and performance comparison
 Applicability analysis
15 May 2014
315 May 2014
Framework
and API overview
4
JDBC key points
 Provides a call-level API for SQL-
based database access
 Oriented towards relational
databases
 The industry standard for database-
independent connectivity
 Fits well for data centric environment
15 May 2014
5
MyBatis key points
 A JDBC Framework
 Couples objects with
stored procedures or SQL
statements
 Provides a mapping engine
that maps SQL parameters
and results to objects in a
declarative way
 It is often a good choice for
legacy or denormalized
databases
15 May 2014
6
Hibernate key points
 A framework for mapping an
object-oriented domain
model to a traditional
relational database
 An implementation of the
Java Persistence API
specification
 Provides wide feature range
and advanced configuration
abilities
 Naturally fits object centric
environment
15 May 2014
715 May 2014
Features and
Performance
8
Benefits & overheads
15 May 2014
Criteria JDBC MyBatis Hibernate
Learning
curve
Simple to learn Simple to learn Many aspects to learn
Work in data
centric env
Good, mapping
efforts exist
Naturally fits Mapping issues, low
performance
Work in obj
centric env
Major mapping
efforts
Good, limited feature
amount
Naturally fits
Object
mapping
Manual, hard to
support
Maps methods to
statements
Transparent
persistence
Query
language
Native SQL Native SQL HQL, Native SQL,
Criteria API
Caching Poor, manual or
3rd party
Good customization 3 level, advanced
customization
Locking Manual or 3rd
party
Manual or 3rd party Out of the box support
9
Performance tests
Test JDBC MyBatis Hibernate
Read 5K
Employees
0.51 0.77 8.09
Create and Insert
10 Employees
0.73 0.9 0.67
Update 10
Employees
0.58 0.55 0.7
Update 10
Employee
Addresses
0.28 0.2 0.41
Cascade delete of
10 Employees
2.25 0.71 0.79
10
Good to keep in mind
 When JDBC is good to use:
– Environment is data centric
– Performance critical sections
– Complex queries that return simple results
 When MyBatis is good to use:
– Environment is data centric
– Development time is essential
– Entities are unclear/complex/compound
– Logic contained in stored procedures
– SQL queries need to be fine-tuned
 When Hibernate is good to use:
– Environment is object centric
– Domain entities are clear and stable
– Variety of CRUD operations required
– Advanced cache support required
11
Questions
12
Your
QR Code
I am at your disposal in case
of any questions or doubts
15 May 2014
Eugene Varfolomeev
Dnepropetrovsk
EVarfolomeev@luxoft.com

Евгений Варфоломеев "Hibernate vs my batis vs jdbc: is there a silver bullet?"

  • 1.
    Hibernate vs MyBatisvs JDBC: is there a silver bullet? Eugene Varfolomeev Dnepropetrovsk 15 May 2014
  • 2.
    2 What is thispresentation about?  Framework and API fundamental principles overview  Features and performance comparison  Applicability analysis 15 May 2014
  • 3.
  • 4.
    4 JDBC key points Provides a call-level API for SQL- based database access  Oriented towards relational databases  The industry standard for database- independent connectivity  Fits well for data centric environment 15 May 2014
  • 5.
    5 MyBatis key points A JDBC Framework  Couples objects with stored procedures or SQL statements  Provides a mapping engine that maps SQL parameters and results to objects in a declarative way  It is often a good choice for legacy or denormalized databases 15 May 2014
  • 6.
    6 Hibernate key points A framework for mapping an object-oriented domain model to a traditional relational database  An implementation of the Java Persistence API specification  Provides wide feature range and advanced configuration abilities  Naturally fits object centric environment 15 May 2014
  • 7.
    715 May 2014 Featuresand Performance
  • 8.
    8 Benefits & overheads 15May 2014 Criteria JDBC MyBatis Hibernate Learning curve Simple to learn Simple to learn Many aspects to learn Work in data centric env Good, mapping efforts exist Naturally fits Mapping issues, low performance Work in obj centric env Major mapping efforts Good, limited feature amount Naturally fits Object mapping Manual, hard to support Maps methods to statements Transparent persistence Query language Native SQL Native SQL HQL, Native SQL, Criteria API Caching Poor, manual or 3rd party Good customization 3 level, advanced customization Locking Manual or 3rd party Manual or 3rd party Out of the box support
  • 9.
    9 Performance tests Test JDBCMyBatis Hibernate Read 5K Employees 0.51 0.77 8.09 Create and Insert 10 Employees 0.73 0.9 0.67 Update 10 Employees 0.58 0.55 0.7 Update 10 Employee Addresses 0.28 0.2 0.41 Cascade delete of 10 Employees 2.25 0.71 0.79
  • 10.
    10 Good to keepin mind  When JDBC is good to use: – Environment is data centric – Performance critical sections – Complex queries that return simple results  When MyBatis is good to use: – Environment is data centric – Development time is essential – Entities are unclear/complex/compound – Logic contained in stored procedures – SQL queries need to be fine-tuned  When Hibernate is good to use: – Environment is object centric – Domain entities are clear and stable – Variety of CRUD operations required – Advanced cache support required
  • 11.
  • 12.
  • 13.
    Your QR Code I amat your disposal in case of any questions or doubts 15 May 2014 Eugene Varfolomeev Dnepropetrovsk EVarfolomeev@luxoft.com