Hibernate - PowerPoint PPT Presentation

1 / 12
About This Presentation
Title:

Hibernate

Description:

http://www.onjava.com/pub/a/onjava/2005/09/21/what-is-hibernate.html. Saves ... join payment.currentStatus as status. join payment.statusChanges as statusChange ... – PowerPoint PPT presentation

Number of Views:66
Avg rating:3.0/5.0
Slides: 13
Provided by: danielk1
Category:
Tags: hibernate

less

Transcript and Presenter's Notes

Title: Hibernate


1
Hibernate
An object-relational mapping tool for Java
by Dan Kigelman
2
Scenario
  • Too many books, too few readers
  • Want to share with friends (mock-library)
  • Need to keep track of
  • title
  • author
  • description
  • available?
  • current location

3
It starts with an object
4
Direct Java JDBC Approach
  • Imagine
  • more classes
  • more methods

Cons
  • Tedious
  • Repetative
  • Error-prone
  • DB-specific

Pros
  • Very flexible
  • Direct access to SQL

5
Object-relational mapping (ORM)
  • Maps java objects to database
  • tendency towards enlightened lazinesshttp//www
    .onjava.com/pub/a/onjava/2005/09/21/what-is-hibern
    ate.html
  • Saves time and sanity
  • Usually at the loss of flexibility
  • (ORM controversy)
  • Many ORM tools exist

6
Hibernate features
  • Unobtrusive few changes to java classes
  • We keep our Plain Old Java Objects
  • Class must have no-parameter constructor
  • Class must follow java naming convention for
    attributes, getters, and setters
  • Open-source (LGPL)
  • Vendor-independent
  • Oracle, DB2, Sybase, MS SQL Server, PostgreSQL,
    MySQL, HypersonicSQL, Mckoi SQL, SAP DB,
    Interbase, Pointbase, Progress, FrontBase,
    Ingres, Informix, Firebird
  • Flexible supports object association,
    inheritance, and polymorphism

7
Book.hbm.xml
  • This tells Hibernate which classes to make
    persistent
  • Mapping java class to db fields
  • Hibernate uses get/set methods for each property
  • Highly customizable

8
Hibernate.cfg.xml
  • Select DB Dialect(currently hsql)
  • Creates / updates schema if needed

9
Simple Queries
10
Relations objects as attributes
  • Supports one-to-many, many-to-many relationships
  • Classes behave naturally
  • Changes made to
  • Book.hbm.xml
  • Friend.hbm.xml

public class Friend private String
name private String address private Book
books ... public class Book private Long
id private String title ... private Friend
currentReader ...
11
Advanced Queries
  • Supports both HQL (Hibernate Query Language) and
    SQL
  • Exampleselect count(payment), status.name from
    Payment as payment join payment.currentStatus
    as status join payment.statusChanges as
    statusChangewhere payment.status.name ltgt
    PaymentStatus.AWAITING_APPROVAL or (
    statusChange.timeStamp ( select
    max(change.timeStamp) from
    PaymentStatusChange change where
    change.payment payment ) and
    statusChange.user ltgt currentUser )group by
    status.name, status.sortOrderorder by
    status.sortOrder

12
Resources and References
  • Hibernate.org
  • Getting started quicklyhttp//www.hibernate.org/
    152.html
  • Tutorialhttp//www.hibernate.org/hib_docs/v3/refe
    rence/en/html/tutorial.html
  • Eloquent overview http//www.onjava.com/pub/a/onj
    ava/2005/09/21/what-is-hibernate.html
  • Another tutorialhttp//www.onjava.com/pub/a/onja
    va/2004/01/14/hibernate.html
  • Wikipedia
  • http//en.wikipedia.org/wiki/Object-relational_map
    pingObject-Relational_mapping_utilities
  • http//en.wikipedia.org/wiki/Hibernate_28Java29
  • HypersonicSQL - 100 Java Database (open-source)
  • http//www.hsqldb.org
Write a Comment
User Comments (0)
About PowerShow.com