Hibernate Intro 2
Hibernate Intro 2
Hibernate is
------------
ORM Framework
maps java object to relational db
open source
invented by Gavin King
POJO based
purely used for persistence
Hibernate Architecture
-----------------------
Configuration
--------------
entry point
holds metadata
used to build a SessionFactory
SessionFactory
--------------
heavy weight ,immutable
responsible to provide session objects
typically there is one sessionfactory per db
Session
--------
-light weight
-represents conversation between java application & db
-wraps db connection object
-one appln can open multiple sessions with db
-every session must be associated with transaction
-used to invoke hibernate CRUD methods eg:-save/load/update/delete
Transaction
-----------
allows the application to define units of work-txn
beginTransaction,commit,rollback
_________________________________________________________________
Flow
1)Configuration
2)SessionFactory
3)Session
4)save/load/update/delete
_________________________________________________________________
steps
-----
1)open Eclipse--->select workspace --->select Java perspective---->create a Java
Project
2)Add hibernate jar files
[go to the website http://www.hibernate.org
download jar files]
[Rt click Project-->Build path-->configure build path-->
Libraries-->Add external jars-->select jar files-->OK]
5)
client code [com.hibernate.client package]
-create Configuration object holding xml inf
-using Configuration object create a SessionFactory
-using SessionFactory obtain Session object
-begin transaction
-create POJO object
-using Session object invoke hibernate API methods [save/load/update/delete]
-commit the transaction
Lab)
Store Product information
code,name,price
__________________________________________________________