Introduction To Hibernate
-
Upload
ashishkulkarni -
Category
Technology
-
view
735 -
download
1
description
Transcript of Introduction To Hibernate
![Page 1: Introduction To Hibernate](https://reader036.fdocuments.us/reader036/viewer/2022082916/54c048ee4a795954368b46e7/html5/thumbnails/1.jpg)
11 March 2009 www.ashishkulkarni.com 1
Introduction to Hibernate
Ashish Kulkarni
![Page 2: Introduction To Hibernate](https://reader036.fdocuments.us/reader036/viewer/2022082916/54c048ee4a795954368b46e7/html5/thumbnails/2.jpg)
www.ashishkulkarni.com 211 March 2009
How this presentation is organised
� A brief history of Relational Databases� The Object Oriented Paradigm� The Problem� Solutions� Demo - The Hibernate Way� Beyond Hibernate� Questions
� Welcome anytime as long as you can accept the following answers:
� I don’t know but I will find out
� Can we park that question and take it up after this presentation?
![Page 3: Introduction To Hibernate](https://reader036.fdocuments.us/reader036/viewer/2022082916/54c048ee4a795954368b46e7/html5/thumbnails/3.jpg)
www.ashishkulkarni.com 311 March 2009
What this Presentation is about
� There is a lot of documentation, books and examples on Hibernate.
� This Presentation doesn’t try to duplicate these. Instead, it tries to show what Hibernate is capable of with the help of real-life examples.
![Page 4: Introduction To Hibernate](https://reader036.fdocuments.us/reader036/viewer/2022082916/54c048ee4a795954368b46e7/html5/thumbnails/4.jpg)
www.ashishkulkarni.com 411 March 2009
A brief history of Relational Databases
� Relational Databases have been around for a long time
� Out of all other database models such as Hierarchical, Network, Object, etc., Relational Databases have come to rule the Database world
� They have come to support a vast array of object types and languages and have gained vast amount of industry support in terms of the sheer number of databases as well as tools
![Page 5: Introduction To Hibernate](https://reader036.fdocuments.us/reader036/viewer/2022082916/54c048ee4a795954368b46e7/html5/thumbnails/5.jpg)
www.ashishkulkarni.com 511 March 2009
The Object Oriented Paradigm
� Java is an Object Oriented language (duh).
� It revels in Object Orientation. POJOs or Plain Old Java Objects form a clean way of storing and passing information within an application.
![Page 6: Introduction To Hibernate](https://reader036.fdocuments.us/reader036/viewer/2022082916/54c048ee4a795954368b46e7/html5/thumbnails/6.jpg)
www.ashishkulkarni.com 611 March 2009
The Problem
� While Java supports a vast array of databases using JDBC, performing any database actions for storing, updating and retrieving data using JDBC can be very cumbersome
� While this can be interesting for extremely small projects, it can put severe constraints on a large scale project and make any change very costly
![Page 7: Introduction To Hibernate](https://reader036.fdocuments.us/reader036/viewer/2022082916/54c048ee4a795954368b46e7/html5/thumbnails/7.jpg)
www.ashishkulkarni.com 711 March 2009
The Problem (continued)
� While a lot of things such as managing database connections can be automated by means of libraries, we still need to write a considerable amount of code for storing and retrieving data from individual tables, setting field level parameters at every stage
� In addition, we need to create and manage transactions
� Transferring Java data types back and forward to Database data types is another issue
![Page 8: Introduction To Hibernate](https://reader036.fdocuments.us/reader036/viewer/2022082916/54c048ee4a795954368b46e7/html5/thumbnails/8.jpg)
www.ashishkulkarni.com 811 March 2009
The Problem (continued)
� Managing relations can be even more tricky with plain JDBC. Just imagine writing code to persist a Parent Java object that Contains an ArrayList or HashSet of Child Java objects within a single transaction. And then, to retrieve it all back into a Java Object Graph.
![Page 9: Introduction To Hibernate](https://reader036.fdocuments.us/reader036/viewer/2022082916/54c048ee4a795954368b46e7/html5/thumbnails/9.jpg)
www.ashishkulkarni.com 911 March 2009
Solutions and Issues
� Some of the early solutions were:�CMP EJBs
� The issue with CMP EJBs was latency due to Lazy Loading, among others
�Custom/Homegrown ORM Frameworks� Maintenance of such homegrown frameworks can
be expensive
![Page 10: Introduction To Hibernate](https://reader036.fdocuments.us/reader036/viewer/2022082916/54c048ee4a795954368b46e7/html5/thumbnails/10.jpg)
www.ashishkulkarni.com 1011 March 2009
Demo – The Hibernate Way
� This demo will show CRUD (Create, Retrieve, Update and Delete) operations using Hibernate in the following scenarios:�Single table with assigned ID
�Parent-Child relationship�Single table with auto-generated ID�Many-Many relationship
![Page 11: Introduction To Hibernate](https://reader036.fdocuments.us/reader036/viewer/2022082916/54c048ee4a795954368b46e7/html5/thumbnails/11.jpg)
www.ashishkulkarni.com 1111 March 2009
What Hibernate Tools can do
� Hibernate Tools can generate Java Classes based on database structure. These Java Classes are referred to as Entities.
� Hibernate Tools can either generate Annotations within the Entities or a separate hbm.xml files for each Entity.
![Page 12: Introduction To Hibernate](https://reader036.fdocuments.us/reader036/viewer/2022082916/54c048ee4a795954368b46e7/html5/thumbnails/12.jpg)
www.ashishkulkarni.com 1211 March 2009
What Hibernate can do
� Hibernate Allows a Java Developer to work with Pure POJOs within the application without having to worry about persistence or database dialect.
� Hibernate can manage the complete lifecycle of an object/entity.
![Page 13: Introduction To Hibernate](https://reader036.fdocuments.us/reader036/viewer/2022082916/54c048ee4a795954368b46e7/html5/thumbnails/13.jpg)
www.ashishkulkarni.com 1311 March 2009
Hibernate Lifecycle
![Page 14: Introduction To Hibernate](https://reader036.fdocuments.us/reader036/viewer/2022082916/54c048ee4a795954368b46e7/html5/thumbnails/14.jpg)
www.ashishkulkarni.com 1411 March 2009
Beyond Hibernate
� With EJB 3 and JPA, Sun has incorporated much of Hibernate into the standard. Hibernate and TopLink are the 2 available Persistence Providers for JPA, Hibernate being the strong favourite.
� Hibernate itself is still expanding. Hibernate Search brings full-text indexes and Google-like search capabilities to any traditional database application.
![Page 15: Introduction To Hibernate](https://reader036.fdocuments.us/reader036/viewer/2022082916/54c048ee4a795954368b46e7/html5/thumbnails/15.jpg)
www.ashishkulkarni.com 1511 March 2009
Questions
![Page 16: Introduction To Hibernate](https://reader036.fdocuments.us/reader036/viewer/2022082916/54c048ee4a795954368b46e7/html5/thumbnails/16.jpg)
www.ashishkulkarni.com 1611 March 2009
Where to go from here
� Me – [email protected]� My website – www.ashishkulkarni.com� www.hibernate.org� Books:
� Manning – Java Persistence with Hibernate – Bauer and King
![Page 17: Introduction To Hibernate](https://reader036.fdocuments.us/reader036/viewer/2022082916/54c048ee4a795954368b46e7/html5/thumbnails/17.jpg)
www.ashishkulkarni.com 1711 March 2009
A bit about me
� I am a Java Contractor currently contracting with JP Morgan in Glasgow. Apart from contracting, I am actively working with other developers at my company to develop bespoke software for privateclients.
� I have been using JBoss Seam, Spring and Hibernate driven JPA for a couple of years now and am absolutely loving it.
� Having worked on FoxPro, Oracle, Visual C++ and SAP in the past,I have 15 years of development experience.
� I have been using Java since 2000 which to this day remains my favourite computer language.
� I have worked in a variety of industries such as Retail Banking,Investment Banking, Financial Institutions, Pharmaceuticals, Manufacturing, Automobiles and Telecommunications.