SlideShare a Scribd company logo
Let’s Hibernate  A brief introduction to Hibernate persistence service Rafael Coutinho (rcouto@br.ibm.com)
Topics to be addressed Introduction to O/R Mapping What is Hibernate? Why Hibernate? Simple Example Features Tools Conclusions Questions
Object/Relational mapping Motivation Development is Object Oriented Current main development languages Java, C++, C# Current main enterprises enviroments Websphere, JBoss, .Net Data needs to be persisted Current main DBMS are relational DB2, Oracle, MySQL.
Object/Relational mapping Why Mapping? Objects needs to be persisted OODBMS didn’t sell Get the best of two worlds Relational: Information management Object: behavior Relational know-how and tools
Object/Relational mapping Why a mapping engine? Even knowing how to map object to relational models Developers stay focused on the object model Isolates relational world from objects Have more robust structural mapping Data access layer creation is tedious Less interesting the work is, higher the risk of errors. Don’t re-invent the wheel !!!
What is Hibernate? Opensource object / relational mapping tool Persistence service Non intrusive approach Uses XML mapping files Currently in version 3.1.3  (April 12 2006)  Provides transparent persistence for POJO
Why Hibernate? Open Source (LGPL) Doesn’t need to be so free Mature software driven by user requests Popular (15.000 downloads/month) No application server needed Java and .Net
Architecture Overview XML  Configuration Hibernate Database Application Persisted Objects XML Mappings
Simple Example Person Address
Simple Example … <hibernate-mapping> <class  name = &quot;vo.Address&quot;   table = &quot;address&quot; > <id  name = &quot;id&quot;   column = &quot;id&quot; > <generator  class = &quot;increment&quot;  /> </id> <property  name = &quot;address&quot; />  </class> </hibernate-mapping> Address.hbm.xml
Simple Example … <hibernate-mapping> <class  name = &quot;vo.Person&quot;   table = &quot;person&quot; > <id  name = &quot;id&quot;   column = &quot;id&quot; > <generator  class =&quot;increment&quot; /> </id> <one-to-one  name = &quot;address&quot;   class = &quot;vo.Address&quot;   constrained = &quot;true&quot;   foreign-key = &quot;addressid&quot;  /> <property  name = &quot;name&quot;   type = &quot;string&quot; > <column  name = &quot;name&quot;  /> </property> </class> </hibernate-mapping> Person.hbm.xml
Simple Example Hibernate.cfg.xml <hibernate-configuration> <session-factory  name = &quot;Diagra&quot; > <property  name = &quot;hibernate.connection.username&quot; > userid   </property> <property  name = &quot;hibernate.connection.password&quot; > wantmommy   </property> <property  name = &quot;hibernate.dialect&quot; > org.hibernate.dialect.MySQLDialect  </property> <property  name = &quot;hibernate.connection.url&quot; > jdbc:mysql:///test  </property> <property  name = &quot;hibernate.connection.driver_class&quot; > com.mysql.jdbc.Driver  </property> <mapping  resource = &quot;Address.hbm.xml&quot; /> <mapping  resource = &quot;Person.hbm.xml&quot; /> </session-factory> </hibernate-configuration>
Code sample Open Session: Session session = HibernateUtils.currentSession(); Transaction tx = session.beginTransaction(); Load: Person aPerson = (Person) session.load(Person. class , personId); Store: session.save(aPerson); List: List result = session.createQuery(&quot; from Person &quot;).list(); Close Session:  tx.commit();  HibernateUtils.closeSession();
Features Transparent persistence Any class can be a  persistent  class (POJO) Nonintrusive No interface or base classes No source or byte-code generation/processing But at runtime Extensible type system User-defined types  Automatic dirty checking Detached object support Constraint transparency Foreign keys Needs no argument constructor Cascading
Features Flexible O/R mapping Driven by XML mapping Supports some inheritance table per class hierarchy  table per subclass  table per concrete class  implicit polymorphism  Support one-to-many, one-to-one and many-to-many Bidirectional and unidirectional associations (dependent objects)
Features Simple API Core for application Extension API for customization Object-Oriented query language HQL (Hibernate query language)  SQLlike Support polymorphic queries Native SQL
Features Operate in managed and non-managed environment J2EE  Can be configured via JMX(Java Management Extension) Can be integrated with application server transactions via JTA (Java Transaction API) Stand-alone application .Net
Features High performance Lazy Loading Fetching Strategies Retrieve associated objects Support for optimistic concurrency control Automatic versioning and time stamping
Development Scenarios Allow four development scenarios Top Down Start with JavaBeans Bottom Up  Start with relational schema Middle out Start with the mapping Meet-in-middle Start with both JavaBeans and relational schema
Tools Hibernate Tools 3 UML Model  XML/XMI POJO Java Source Mapping  Metadata Database Schema AndroMDA  XDoclet  SchemaExport  (hbm2ddl) Middlegen   CodeGenerator  (hbm2java)
Tools Eclipse IDE Plugin Wizard to Create Configuration File XML Mapping Editor Context dependent code completion in the XML mapping editor
Tools Hibernate Console   View Entity Structure Prototype Queries Properties view
Tools Reverse engineering  Code generation Mapping files  generation Configuration file  generation
Hands on Real life example
Conclusion Data access layer creation is tedious Automatic mapping is needed Mature robust software Open source No application servers needed Development tools No silver bullet
References Hibernate Website www.hibernate.org Tutorial www.gloegl.de/17.html Hibernate tools http://www.hibernate.org/255.html http://www.jboss.com/products/seam/SeamHBTools.html
Questions & maybe answers E-mail: rcouto@br.ibm.com
Questions I do have!!! Next presentation on May 10 th !

More Related Content

What's hot (20)

PPTX
Introduction to JavaScript Programming
Raveendra R
 
PPTX
Play Your API with MuleSoft API Notebook
Rakesh Kumar Jha
 
PPT
Java script final presentation
Adhoura Academy
 
PPTX
Internet and Web Technology (CLASS-14) [JSP] | NIC/NIELIT Web Technology
Ayes Chinmay
 
PPT
Web development basics (Part-4)
Rajat Pratap Singh
 
PDF
Basic JavaScript Tutorial
DHTMLExtreme
 
KEY
Object oriented javascript
Garrison Locke
 
PPT
JavaScript Workshop
Pamela Fox
 
PPTX
Javascript 01 (js)
AbhishekMondal42
 
PPT
Introduction to JavaScript
Andres Baravalle
 
PPTX
Javascript
Nagarajan
 
PPT
Java Script ppt
Priya Goyal
 
PDF
Wt unit 2 ppts client side technology
PUNE VIDYARTHI GRIHA'S COLLEGE OF ENGINEERING, NASHIK
 
PPT
AJAX Workshop Notes
Pamela Fox
 
PDF
JavaScript - Chapter 3 - Introduction
WebStackAcademy
 
PPTX
Java script
Jay Patel
 
PDF
Baby steps to Domain-Driven Design
Žilvinas Kuusas
 
PPTX
GTAC 2010 -
narayanraman
 
Introduction to JavaScript Programming
Raveendra R
 
Play Your API with MuleSoft API Notebook
Rakesh Kumar Jha
 
Java script final presentation
Adhoura Academy
 
Internet and Web Technology (CLASS-14) [JSP] | NIC/NIELIT Web Technology
Ayes Chinmay
 
Web development basics (Part-4)
Rajat Pratap Singh
 
Basic JavaScript Tutorial
DHTMLExtreme
 
Object oriented javascript
Garrison Locke
 
JavaScript Workshop
Pamela Fox
 
Javascript 01 (js)
AbhishekMondal42
 
Introduction to JavaScript
Andres Baravalle
 
Javascript
Nagarajan
 
Java Script ppt
Priya Goyal
 
Wt unit 2 ppts client side technology
PUNE VIDYARTHI GRIHA'S COLLEGE OF ENGINEERING, NASHIK
 
AJAX Workshop Notes
Pamela Fox
 
JavaScript - Chapter 3 - Introduction
WebStackAcademy
 
Java script
Jay Patel
 
Baby steps to Domain-Driven Design
Žilvinas Kuusas
 
GTAC 2010 -
narayanraman
 

Similar to Basic Hibernate Final (20)

PPT
Apache Persistence Layers
Henning Schmiedehausen
 
PPT
Patni Hibernate
patinijava
 
PPTX
Javazone 2010-lift-framework-public
Timothy Perrett
 
PPT
Intro to-html-backbone
zonathen
 
PPT
Boston Computing Review - Java Server Pages
John Brunswick
 
PPT
I Feel Pretty
John Quaglia
 
ODP
Ldap Synchronization Connector @ 2011.RMLL
sbahloul
 
PPTX
Dynamic Language Performance
Kevin Hazzard
 
PPT
Persisting Your Objects In The Database World @ AlphaCSP Professional OSS Con...
Baruch Sadogursky
 
PPT
RomaFramework Tutorial Basics
Luca Garulli
 
PPT
Introduction to Alfresco Surf Platform
Alfresco Software
 
ODP
JavaEE Spring Seam
Carol McDonald
 
PPT
Ajax to the Moon
davejohnson
 
ODP
REST dojo Comet
Carol McDonald
 
PPTX
Building AOL's High Performance, Enterprise Wide Mail Application With Silver...
goodfriday
 
PPT
Dev381.Pp
Severus Prime
 
PPT
Struts2
Scott Stanlick
 
PPT
PowerPoint
Videoguy
 
ODP
A Complete Tour of JSF 2
Jim Driscoll
 
Apache Persistence Layers
Henning Schmiedehausen
 
Patni Hibernate
patinijava
 
Javazone 2010-lift-framework-public
Timothy Perrett
 
Intro to-html-backbone
zonathen
 
Boston Computing Review - Java Server Pages
John Brunswick
 
I Feel Pretty
John Quaglia
 
Ldap Synchronization Connector @ 2011.RMLL
sbahloul
 
Dynamic Language Performance
Kevin Hazzard
 
Persisting Your Objects In The Database World @ AlphaCSP Professional OSS Con...
Baruch Sadogursky
 
RomaFramework Tutorial Basics
Luca Garulli
 
Introduction to Alfresco Surf Platform
Alfresco Software
 
JavaEE Spring Seam
Carol McDonald
 
Ajax to the Moon
davejohnson
 
REST dojo Comet
Carol McDonald
 
Building AOL's High Performance, Enterprise Wide Mail Application With Silver...
goodfriday
 
Dev381.Pp
Severus Prime
 
PowerPoint
Videoguy
 
A Complete Tour of JSF 2
Jim Driscoll
 
Ad

Basic Hibernate Final

  • 1. Let’s Hibernate A brief introduction to Hibernate persistence service Rafael Coutinho ([email protected])
  • 2. Topics to be addressed Introduction to O/R Mapping What is Hibernate? Why Hibernate? Simple Example Features Tools Conclusions Questions
  • 3. Object/Relational mapping Motivation Development is Object Oriented Current main development languages Java, C++, C# Current main enterprises enviroments Websphere, JBoss, .Net Data needs to be persisted Current main DBMS are relational DB2, Oracle, MySQL.
  • 4. Object/Relational mapping Why Mapping? Objects needs to be persisted OODBMS didn’t sell Get the best of two worlds Relational: Information management Object: behavior Relational know-how and tools
  • 5. Object/Relational mapping Why a mapping engine? Even knowing how to map object to relational models Developers stay focused on the object model Isolates relational world from objects Have more robust structural mapping Data access layer creation is tedious Less interesting the work is, higher the risk of errors. Don’t re-invent the wheel !!!
  • 6. What is Hibernate? Opensource object / relational mapping tool Persistence service Non intrusive approach Uses XML mapping files Currently in version 3.1.3 (April 12 2006) Provides transparent persistence for POJO
  • 7. Why Hibernate? Open Source (LGPL) Doesn’t need to be so free Mature software driven by user requests Popular (15.000 downloads/month) No application server needed Java and .Net
  • 8. Architecture Overview XML Configuration Hibernate Database Application Persisted Objects XML Mappings
  • 10. Simple Example … <hibernate-mapping> <class name = &quot;vo.Address&quot; table = &quot;address&quot; > <id name = &quot;id&quot; column = &quot;id&quot; > <generator class = &quot;increment&quot; /> </id> <property name = &quot;address&quot; /> </class> </hibernate-mapping> Address.hbm.xml
  • 11. Simple Example … <hibernate-mapping> <class name = &quot;vo.Person&quot; table = &quot;person&quot; > <id name = &quot;id&quot; column = &quot;id&quot; > <generator class =&quot;increment&quot; /> </id> <one-to-one name = &quot;address&quot; class = &quot;vo.Address&quot; constrained = &quot;true&quot; foreign-key = &quot;addressid&quot; /> <property name = &quot;name&quot; type = &quot;string&quot; > <column name = &quot;name&quot; /> </property> </class> </hibernate-mapping> Person.hbm.xml
  • 12. Simple Example Hibernate.cfg.xml <hibernate-configuration> <session-factory name = &quot;Diagra&quot; > <property name = &quot;hibernate.connection.username&quot; > userid </property> <property name = &quot;hibernate.connection.password&quot; > wantmommy </property> <property name = &quot;hibernate.dialect&quot; > org.hibernate.dialect.MySQLDialect </property> <property name = &quot;hibernate.connection.url&quot; > jdbc:mysql:///test </property> <property name = &quot;hibernate.connection.driver_class&quot; > com.mysql.jdbc.Driver </property> <mapping resource = &quot;Address.hbm.xml&quot; /> <mapping resource = &quot;Person.hbm.xml&quot; /> </session-factory> </hibernate-configuration>
  • 13. Code sample Open Session: Session session = HibernateUtils.currentSession(); Transaction tx = session.beginTransaction(); Load: Person aPerson = (Person) session.load(Person. class , personId); Store: session.save(aPerson); List: List result = session.createQuery(&quot; from Person &quot;).list(); Close Session: tx.commit(); HibernateUtils.closeSession();
  • 14. Features Transparent persistence Any class can be a persistent class (POJO) Nonintrusive No interface or base classes No source or byte-code generation/processing But at runtime Extensible type system User-defined types Automatic dirty checking Detached object support Constraint transparency Foreign keys Needs no argument constructor Cascading
  • 15. Features Flexible O/R mapping Driven by XML mapping Supports some inheritance table per class hierarchy table per subclass table per concrete class implicit polymorphism Support one-to-many, one-to-one and many-to-many Bidirectional and unidirectional associations (dependent objects)
  • 16. Features Simple API Core for application Extension API for customization Object-Oriented query language HQL (Hibernate query language) SQLlike Support polymorphic queries Native SQL
  • 17. Features Operate in managed and non-managed environment J2EE Can be configured via JMX(Java Management Extension) Can be integrated with application server transactions via JTA (Java Transaction API) Stand-alone application .Net
  • 18. Features High performance Lazy Loading Fetching Strategies Retrieve associated objects Support for optimistic concurrency control Automatic versioning and time stamping
  • 19. Development Scenarios Allow four development scenarios Top Down Start with JavaBeans Bottom Up Start with relational schema Middle out Start with the mapping Meet-in-middle Start with both JavaBeans and relational schema
  • 20. Tools Hibernate Tools 3 UML Model XML/XMI POJO Java Source Mapping Metadata Database Schema AndroMDA XDoclet SchemaExport (hbm2ddl) Middlegen CodeGenerator (hbm2java)
  • 21. Tools Eclipse IDE Plugin Wizard to Create Configuration File XML Mapping Editor Context dependent code completion in the XML mapping editor
  • 22. Tools Hibernate Console View Entity Structure Prototype Queries Properties view
  • 23. Tools Reverse engineering Code generation Mapping files generation Configuration file generation
  • 24. Hands on Real life example
  • 25. Conclusion Data access layer creation is tedious Automatic mapping is needed Mature robust software Open source No application servers needed Development tools No silver bullet
  • 26. References Hibernate Website www.hibernate.org Tutorial www.gloegl.de/17.html Hibernate tools http://www.hibernate.org/255.html http://www.jboss.com/products/seam/SeamHBTools.html
  • 28. Questions I do have!!! Next presentation on May 10 th !

Editor's Notes

  • #17: Metadata API for dynamic mapping change????