June 26, 2017 3
•DAO Overview
- what is Dao
- Features of Dao
-Database access with Dao
• ORM
- what is ORM
-Advantages of ORM
•ORM tools
-Hibernate
-Ibatis
-OJB
-JPA
•Comparision Between Tools
•CONCLUSION
Agenda
June 26, 2017 4
• What is DAO?
The Data Access Object is basically an object or an interface that provides
access to an underlying database or any other persistence storage.
Features of DAO
•DAO is used in a large percentage of applications where data storage is
required.
•It hides all details of data storage from the rest of the application.
•It act as an intermediary between your application and the database. They
move data back and forth between Java objects and database records.
•It also allow ripple effects from possible changes to the persistence
mechanism to be confined to a specific area.
DAO Overview
Databases You Can Access with DAO
• Microsoft Excel, versions 3.0, 4.0, 5.0, and 7.0 worksheets
• Lotus WKS, WK1, WK3, and WK4 spreadsheets
• Text files
• Databases using the Microsoft Jet database engine, created
with Microsoft Access or Microsoft Visual Basic, versions 1.x,
2.x, and 3.0 of the database engine
• Installable ISAM databases, including:
– dBASE III, dBASE IV, and dBASE 5.0
– Paradox, versions 3.x, 4.x, and 5.x
June 26, 2017 5
Databases
June 26, 2017 6
•ORM(Object-relational mapping)
ORM stands for Object-Relational Mapping (ORM) is a programming
technique for converting data between relational databases and object
oriented programming languages
ORM tools:
•Hibernate
•OJB (ObjectRelationalBridge)
•iBATIS
•JPA
ORM Overview
Advantages of ORM
• ORM tools provide a host of services thereby allowing developers to
focus on the business logic of the application rather than repetitive
CRUD (Create Read Update Delete) logic.
• ORM tools provide an object oriented query language. This allows
application developers to focus on the object model and not to have to
be concerned with the database structure or SQL semantics.
• Facilitates implementing the Domain Model pattern
• Support for multiple users updating the same data simultaneously.
• Key Management. Identifiers and surrogate keys are automatically
propogated and managed.
• Eliminates lots of repetitive code and focus on business logic.
June 26, 2017 7
ORM Overview
June 26, 2017 8
• Hibernate ?
Hibernate is an open source, lightweight, ORM tool which maps Java
classes to database tables and from Java data types to SQL data types
• Features of Hibernate ?
•Hibernate takes care of mapping Java classes to database tables using
XML files and without writing any line of code.
•Provides simple APIs for storing and retrieving Java objects directly to
and from the database.
•If there is change in Database or in any table then the only need to
change XML file properties.
Hibernate Overview
June 26, 2017 9
•Features of Hibernate?
•Abstract away the unfamiliar SQL types and provide us to work around familiar
Java Objects.
•Hibernate does not require an application server to operate.
•Supported Databases:
•HSQL Database Engine
•DB2/NT
•MySQL
•PostgreSQL
•FrontBase
•Oracle
•Microsoft SQL Server Database
•Sybase SQL Server
Hibernate Overview
June 26, 2017 10
•Supported Technologies:
•XDoclet Spring
•J2EE
•Eclipse plug-ins
•Maven
Hibernate Overview
June 26, 2017 11
•iBATIS
iBATIS is a persistence framework which automates the mapping
between SQL databases and objects in Java, .NET, and Ruby on Rails.
Advantages of iBatis
•Supports stored procedures − iBATIS encapsulates SQL in the form of
stored procedures so that business logic is kept out of the database, and
the application is easier to deploy and test, and is more portable.
•Supports inline SQL − No precompiler is needed, and you have full
access to all of the features of SQL.
•Supports dynamic SQL − iBATIS provides features for dynamically
building SQL queries based on parameters.
•Supports O/RM − iBATIS supports many of the same features as an
O/RM tool, such as lazy loading, join fetching, caching, runtime code
generation, and inheritance
iBATIS Overview
•OJB
ObJectRelationalBridge (OJB) is an Object/Relational mapping
tool that allows transparent persistence for Java Objects
against relational databases.
Features of OJB?
• It is easy to integrate into an existing application because it
does not generate code.
• It allows the use of different patterns of persistence
• It is lightweight and easy to configure two files to implement a
persistence layer
June 26, 2017 12
OJB Overview
•JPA
Java Persistence API is a collection of classes and methods to
persistently store the vast amounts of data into a database
which is provided by the Oracle Corporation.
Features of JPA?
• It is easier to use a stored procedure to perform the
operations within the database
• Using JPA, the burden of interacting with the database reduces
significantly.
• It forms a bridge between object models (Java program) and
relational models
June 26, 2017 13
JPA Overview
COMPARISON OF POWERFUL ORM TOOLS
iBATIS HIBERNATE JPA
iBATIS is simpler. It
comes in a much smaller
package size.
Hibernate generates SQL
automatically
JPA is simple
iBATIS is flexible. It
offers faster development
time.
Hibernate is highly
scalable. It provides a
much more advanced
cache.
JPA is scalable and
provides several
advantages for java
developers for data
binding process
iBATIS uses SQL which
could be database
dependent.
Hibernate uses HQL which
is relatively independent
of databases. It is easier
to change db in Hibernate.
JPA uses JPQL which is
similar to the syntax of
SQL
June 26, 2017 14
ORM Tools
COMPARISON OF POWERFUL ORM TOOLS
iBATIS HIBERNATE JPA
iBatis maps the Result
Set from JDBC API to
your POJO Objects, so
you don’t have to care
about table structures.
Hibernate maps your
Java POJO objects to
the Database tables.
JPA uses metadata
annotations and/or XML
descriptor files to
configure the mapping
between Java objects in
the application domain and
tables in the relational
database.
It supports caching It provides much
more advance cache
It does not support
caching
June 26, 2017 15
ORM Tools
COMPARISION BETWEEN TOOLS
June 26, 2017 16
Features Hibernate iBATIS JPA
Simplicity Best Good Good
Complete ORM
solution
Average Best Best
Adaptability to data
model changes
Good Average Average
Complexity Best Average Average
Dependence on SQL Good Average Average
ORM Tools
COMPARISION BETWEEN TOOLS
June 26, 2017 17
Features Hibernate iBATIS JPA
Performance Best Best N/A*
Portability across
different relational
database
Average Best N/A*
Portability to non-
Java platforms
Best Good Not Supported
Community support
and documentation
Average Good Good
ORM Tools
CONCLUSION
There are major differences between iBATIS and Hibernate
and JPA. Every solutions work well, given their specific domain.
iBATIS is suggested in case −
• You want to create your own SQL's and you are willing to maintain
them.
• Your environment is driven by relational data model.
• You have to work on existing and complex schemas.
• Use Hibernate if the environment is driven by object model and
needs to generate SQL automatically.
• JPA is defined to work with relational databases only. If your
persistence solution needs to be extended to other types of
data stores, like XML databases, then JPA is not the answer to
your persistence problem.
June 26, 2017 18
Conclusion