0% found this document useful (0 votes)
6 views2 pages

Hibernate Intro 2

Uploaded by

vishalwdv
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views2 pages

Hibernate Intro 2

Uploaded by

vishalwdv
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

29-Sep

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

_________________________________________________________________

Employee e=new Employee(101,"Robert",89000); //transient object


session.save(e); //persistent object
_________________________________________________________________

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]

3)create the POJO class[com.hibernate.model]

4)Do the mapping in xml files[keep in src folder]


[metadata-XML/Annotation]
i)hibernate.cfg.xml [Hibernate Configuration file]
DB driver,url,user,pass
connection pool size,show_sql,dialect
name of the class table mapping file

ii)**.hbm.xml [hbm-Hibernate mapping file]


[Class-Table Mapping file]
table,class,mapping metadata between object & db cols

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

__________________________________________________________

You might also like