An Introduction to Hibernate Matt Secoske

Slides:



Advertisements
Similar presentations
Spring, Hibernate and Web Services 13 th September 2014.
Advertisements

Introduction to the Spring Framework University of Kansas January 2009 This presentation and example application are available at
Hibernate 1. Introduction ORM goal: Take advantage of the things SQL databases do well, without leaving the Java language of objects and classes. ORM.
© 2005, Cornell University. Rapid Application Development using the Kuali Architecture (Struts, Spring and OJB) A Case Study Bryan Hutchinson
Software Services for Social Network tools implementation Aleksandar Dimov, PhD Sofia University
ODBC and JDBC O/R Mapping David Rabinowitz. June 2nd, 2004 Object Oriented Design Course 2 Objects And Databases Most of the applications today are written.
ODBC and JDBC O/R Mapping Amit Shabtay. June 2nd, 2004 Object Oriented Design Course 2 Objects And Databases Most of the applications today are written.
Session-01. Hibernate Framework ? Why we use Hibernate ?
Address - #22, 1 st Floor, Station View Road, Kodambakkam, Chennai JTech Soft Solutions Website:
Intro to Spring CJUG - January What is Spring? “The Spring framework provides central transaction control of various objects.” This means that any.
Using Third-Party Frameworks in Building Blocks™ David Ashman Principal Architect, Product Development.
Spring Framework Adam Waldal Senior Consultant. About me..  OPI is a leader in J2EE consulting with Relationships with BEA, IBM, Tibco, and many other.
Data Persistence and Object-Relational Mapping Slides by James Brucker, used with his permission 1.
Introduction to JPA Java Persistence API Introduction to JPA.
Hibernatification! Roadmap for Migrating from Plain Old SQL on JDBC to JPA on Hibernate Duke Banerjee Senior Developer, DrillingInfo.com.
CSE446 S OFTWARE Q UALITY M ANAGEMENT Spring 2014 Yazılım ve Uyguluma Geliştirme Yöneticisi Orhan Başar Evren.
Training - Day 3 OJB. What is OR Mapping? OR Mapping is the mapping of relational database tables to objects (Java Objects in our case) Many OR Mapping.
2007 JavaOne SM Conference | Session BOF-4181 | BOF-4181 Migrating a Spring/Hibernate Application to Java Platform, Enterprise Edition (Java EE) 5 Adrian.
NetArchive Suite Workshop 2011 Technical Track - Code refactoring with the Spring Framework.
Introduction to the Spring Framework By: Nigusse A. Duguma Kansas State university Department of Computer Science Nov 20, 2007.
April 05 Prof. Ismael H. F. Santos - 1 Modulo II Spring-MVC Controllers Prof. Ismael H F Santos.
UPortal Developers MIT August 2004 Persistence Strategy for uPortal 3 Mike DeSimone the r-smart group
Agenda What is Hibernate Spring Integration Questions Overview
Maven for building Java applications By Nalin De Zoysa
Introduction to the Spring Framework Rajesh. Spring Mission Statement J2EE should be easier to use OO design is more important than any implementation.
NHibernate in Action Web Seminar at UMLChina By Pierre Henri Kuaté 2008/08/27
Entity Beans BMP Celsina Bignoli
Object persistence with Hibernate in Decision Deck 1.1 Gilles Dodinet 2 nd Decision Deck Workshop 2008, February.
OpusCollege and the use of Spring and iBatis
CHAPTER 14 USING RELATIONAL DATABASES TO PROVIDE OBJECT PERSISTENCE (ONLINE) © 2013 Pearson Education, Inc. Publishing as Prentice Hall 1 Modern Database.
JBoss Seam Presented by Andy Nguyen Truc Pham. What is JBoss Seam? Created by Gavin King Created by Gavin King A lightweight framework for Java EE 5.0.
Hibernate Query Language Make SQL be object oriented – Classes and properties instead of tables and columns – Polymorphism – Associations – Much less verbose.
Seminar on. Overview Hibernate. What is it? Hibernate. How does it work? Hibernate Tools.
Object/Relational Mapping with Hibernate Practical ORM.
Spring Framework. Spring Overview Spring is an open source layered Java/J2EE application framework Created by Rod Johnson Based on book “Expert one-on-one.
Object Oriented Analysis and Design 1 Chapter 7 Database Design  UML Specification for Data Modeling  The Relational Data Model and Object Model  Persistence.
© 2011 Pearson Education, Inc. Publishing as Prentice Hall 1 Chapter 14 Using Relational Databases to Provide Object Persistence (Overview) Modern Database.
Spring Database Access Ojitha Kumanayaka Copyright © Virtusa, 2007.
Hibernate Persistence. What is Persistence Persist data to database or other storage.  In OO world, persistence means persist object to external storage.
Hibernate 3.0. What is Hibernate Hibernate is a free, open source Java package that makes it easy to work with relational databases. Hibernate makes it.
Hibernate Introduction - 1 Present by Eric Yu. BeanSoft | 2 Content Understanding object/relational persistence Introduction Architecture The core interfaces.
Java Data Persistence Using Hibernate Jack Gardner October 2004.
Object-Relational Mapping with Hibernate Brian Sam-Bodden Principal Partner Integrallis Software, LLC. August 1 - 5, 2005.
An Introduction to Object/Relational Persistence and Hibernate Yi Li
A U.S. Department of Energy Office of Science Laboratory Operated by The University of Chicago Argonne National Laboratory Office of Science U.S. Department.
JPA / HIBERNATE CSCI 6370 Nilayan Bhattacharya Sanket Sable.
February,2006 Advanced DB System Object Relational Model Prof: Dr Rahgozar Euhanna Ghadimi, Mostafa Keikha Discussion, Implementation.
Text 16 de mayo de 2009 Spring Framework Part III. Portable Service Abstractions Buenos Aires, June 2009.
Topic : Hibernate 1 Kaster Nurmukan. An ORM tool The problem fixed by ORM Advantage Hibernate Hibernate Basic –Hibernate sessionFactory –Hibernate Session.
Copyright 2007 SpringSource. Copying, publishing or distributing without express written permission is prohibited. Introduction to Data Access with Spring.
Kansas City Java User’s Group Jason W. Bedell July 12, 2006
Text 16 de mayo de 2009 Spring Framework Part III. Portable Service Abstractions Buenos Aires, June 2009.
Topic : Hibernate 1 Kaster Nurmukan. An ORM tool Used in data layer of applications Implements JPA.
Introduction – ORM, Helloworld Application
Fundamentals of MyBATIS
Hibernate Basics 廖峻鋒 Sep 14,2004 NTU Dept. of CSIE.
Introduction to ORM Hibernate Hibernate vs JDBC. May 12, 2011 INTRODUCTION TO ORM ORM is a programming technique for converting data between relational.
CS422 Principles of Database Systems Object-Relational Mapping (ORM) Chengyu Sun California State University, Los Angeles.
CS520 Web Programming Object-Relational Mapping with Hibernate and JPA (I) Chengyu Sun California State University, Los Angeles.
CS 440 Database Management Systems Stored procedures & OR mapping 1.
Hibernate Online Training. Introduction to Hibernate Hibernate is a high-performance Object-Relational persistence and query service which takes care.
Современные технологии баз данных Лекция 7. Объектно-реляционное отображение (ORM) Технология отображения объектов какого- либо объектно-ориентированного.
HIBERNATE/Java Overview of technology for Hibernate by محمد حسن کاظمی پوران Master : M.M.Nematollahi.
Training What’s Spring? The leading full-stack Java/JEE application framework.
CS6320 – Java Persistence API
J2EE Lecture 6: Spring – IoC and Dependency Injection
Object/Relational Mapping with Hibernate
Java Data Persistence Using Hibernate
Testing a persistence layer
Developing and testing enterprise Java applications
Presentation transcript:

An Introduction to Hibernate Matt Secoske

Agenda ● What is Hibernate – Overview – Benefits – Example ● Spring Integration – Benefits – Example ● Questions

What is Hibernate? ● Popular Open Source (LGPL) Object/Relational Mapping (ORM) tool ● Transparent persistence for POJOs (Plain Old Java Objects) ● Core of JBoss CMP 2.0 impl.

Object/Relational Mapping JavaObject int id; String name; String getName() int getId() void setName(String) void setId(int) SQL Table id [int] primary key, name [varchar(50)] Magic Happens Here (O/R Mapper – i.e. Hibernate)

Other ORM Solutions “Open” – iBatis SQL Maps – JDO Commercial – TopLink

Why Hibernate? Retains natural object model (transparent) Minimizes Code Does not require a container Model is not tied to persistance implementation

Hibernate's Goal Remove 95% of common data persistence problems

How do you use it? Act on your data model Query in SQL and/or HQL... or using your object model

Auction Object Model

Persistant Class Default Constructor Getters/Setters Collections use interface types Identifier property public class AuctionItem { private Long _id; private Set _bids; private Bid _successfulBid private String _description; public Long getId() { return _id; } private void setId(Long id) { _id = id; } public String getDescription() { return _description; } public void setDescription(String desc) { _description=desc; } … }

XML Mapping Readable metadata Column/Table map Key Generation Collections Fetching Strategies <set name=“bids” cascade=“all” lazy=“true”>

Working with Data Session session = sessionFactory.openSession(); Transaction tx = s.beginTransaction(); AuctionItem item = (AuctionItem) session.get(ActionItem.class, itemId); item.setDescription(newDescription); tx.commit(); session.close(); Retrieve an AuctionItem and change description

Working with Data Retrieve an AuctionItem and create a new persistent Bid Bid bid = new Bid(); bid.setAmount(bidAmount); Session session = sf.openSession(); Transaction tx = session.beginTransaction(); AuctionItem item = (AuctionItem) session.get(ActionItem.class, itemId); bid.setItem(item); item.getBids().add(bid); tx.commit(); session.close();

Hibernate in code Retrieve an AuctionItem and create a new persistent Bid Bid bid = new Bid(); bid.setAmount(bidAmount); Session session = sf.openSession(); Transaction tx = session.beginTransaction(); AuctionItem item = (AuctionItem) session.get(ActionItem.class, itemId); bid.setItem(item); item.getBids().add(bid); tx.commit(); session.close();

Hibernate in code Retrieve an AuctionItem and create a new persistent Bid Session session = sf.openSession(); Transaction tx = session.beginTransaction(); AuctionItem item = (AuctionItem) session.get(ActionItem.class, itemId); tx.commit(); session.close(); item.setDescription(newDescription); Session session2 = sf.openSession(); Transaction tx = session2.beginTransaction(); session2.update(item); tx.commit(); session2.close();

Benefits Metadata controlled persistence Transparent - working with the model, not the data access technology Pooling, Caching, Transactions can all be handled outside of our code

Integrating Spring and Hibernate

Spring and Hibernate ● Benefits ● Examples

Benefits Resource Management – IoC / AOP Session Management Extended Transaction Support – JTA and/or JDBC – Flexible Transaction Demarcation Programmatic Declarative (Spring's XML config) HibernateTemplate – Simplifies Hibernate API

Spring IoC Session POJO DAO setSession() save()

Spring Interceptors (AOP) Business Logic getCatById() save(Cat) DAOInterceptor Session Spring Framework

Spring’s HibernateTemplate Hibernate Only: HibernateTemplate: public User getUserBy Address(final String ) { try { Session session = sessionFactory.openSession(); List list = session.find( "from User user where user. =?", , Hibernate.STRING); return (User) list.get(0); } finally { session.close(); } } public User getUserBy Address(final String ) { List list = getHibernateTemplate().find( "from User user where user. =?", , Hibernate.STRING); return (User) list.get(0); }

News of the day (12/20/2004) ● Hibernate 3.0 Beta 1 released! – Features: ● Virtualization (Filters, Permissions, etc) ● New mapping constructs ● HQL rewrite – using ANTLR ● Representation Independence – i.e.HashMap ● Statistics and JMX Monitoring ● Stored Procedures / Handwritten SQL ● … Much more

Important Links ● ● Parts of this presentation come from documentation and presentations on the hibernate.org website: - Manual - Presentation by Gavin King - Road Map Books: J2EE Development without EJB – Rod Johnson and Juergen Hoeller Better, Faster, Lighter Java – Bruce A. Tate and Justin Gehtland Hibernate in Action – Christian Bauer and Gavin King

Questions ● ???