Hibernate Intro
Hibernate Intro
JDBC
• JDBC stands for Java Database Connectivity and provides a
set of API for accessing relational DB. These APIs enables
programs to execute SQL statements and interact with any
SQL compliant database.
Cons
• Complex if it is used in large projects
• Large programming overhead
• No encapsulation
• Hard to implement MVC concept
• Query is DBMS specific
Mismatch Problems
Mismatch Description
Granularity Sometimes you will have an object model which has more classes
than the number of corresponding tables in the database.
Inheritance RDBMSs do not define anything similar to Inheritance which is a
natural paradigm in object-oriented programming languages.
Identity A RDBMS defines exactly one notion of 'sameness': the primary key.
Java, however, defines both object identity (a==b) and object equality
(a.equals(b)).
Associations Object-oriented languages represent associations using object
references where as am RDBMS represents an association as a
foreign key column.
Navigation The ways you access objects in Java and in a RDBMS are
fundamentally different.
Need for Mapping
• When we work with an object-oriented systems, there's a
mismatch between the object model and the relational
database
• The session objects should not be kept open for a long time because they
are not usually thread safe and they should be created and destroyed as
needed.
Transaction Object
• A Transaction represents a unit of work with the database and most of the
RDBMS supports transaction functionality. Transactions in Hibernate are
handled by an underlying transaction manager and transaction (from JDBC
or JTA).