Евгений Варфоломеев "Hibernate vs my batis vs jdbc: is there a silver bullet?"
1. Hibernate vs MyBatis vs JDBC:
is there a silver bullet?
Eugene Varfolomeev
Dnepropetrovsk
15 May 2014
2. 2
What is this presentation about?
Framework and API fundamental principles overview
Features and performance comparison
Applicability analysis
15 May 2014
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
8. 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
10. 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