Why Hibernate and not JDBC?

  • JDBC maps Java classes to database tables (and from Java data types to SQL data types)
  • Hibernate automatically generates the SQL queries.
  • Hibernate provides data query and retrieval facilities and can significantly reduce development time otherwise spent with manual data handling in SQL and JDBC.
  • Makes an application portable to all SQL databases.
Hibernate vs. JDBC (an example)
JDBC tuple insertion
st.executeUpdate("INSERT INTO book VALUES("Harry Potter","J.K.Rowling"));
Hibernate tuple insertion
session.save(book1);

High-Level View

Hibernate High level view

Minimal Architecture

  • The "minimal" architecture has the application manage its own JDBC connections and provide those connections to Hibernate; additionally the application manages transactions for itself.
Minimal Architecture

Comprehensive Architecture

  • The "comprehensive" architecture abstracts the application away from the underlying JDBC/JTA APIs and allows Hibernate to manage the details.
Comprehensive Architecture