0% found this document useful (0 votes)
7 views

Hibernate Intro 1

Uploaded by

vishalwdv
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

Hibernate Intro 1

Uploaded by

vishalwdv
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

28-Sep Day1

-------------
Trainer Name:Monal Zope
BE Computers in 2001

Module:Hibernate & Spring [Adv Java Book2]


Duration:40 hrs

Today we starting with module Hibernate

Hibernate is a Framework??
--------------------------
Framework is semi-developed code which can be customized to develop our application
faster

we dont to develop our application from scratch

we acheive RAD[Rapid Application Development]

Object Persistence
------------------
we want to store object state permanently
Employee e=new Employee(101,"RObert",78900);

Java Domain----Hierarchical structure


RDBMS Domain----Tabular structure

we are trying map object to the database

Application Layers
--------------------

Presentation Layer[UI]--->Swing,HTML,JSP
Business Layer[Business logic]--->Java Bean,EJB,Servlet
Persistence Layer[Data Access]--->Hibernate,JDBC

Persistence Mechanisms
----------------------
1)JDBC:-
-----
application connects to the db via DriverManager/
DataSource[Connection Pooling]

appln fires query using Statement,PreparedStatement, CallableStatement

To retrive data ResultSet/RowSet is used


Pros:-
simple to code

Cons:-
repeated coding
transaction & concurrency needs to be done manually
caching & dynamic update require extra efforts
___________________________________________________________

2)Serialization
--------------
Serialization is process of converting object state into a bytestream.
This bytestream can then be stored into file/transfer across network

Pros:-
automated object peristence in a file
[
we just need to pass object to a method writeObject()
class need to implements Serializable
]
Cons:-
object--->bytestream---->file [slow]
hence not suitable for large scale data

public class Employee implements Serializable{


int empId;
transient String empName; //not serialized
double salary;
}
oos.writeObject(emp);
___________________________________________________________

3)XML:- Extensible Markup language


----
employee.xml
<Employee>
<id>101</id>
<name>RObert</name>
<salary>78900</salary>
</Employee>

Pros:-
stores structured data in a text format[hence best suited for transferring data
between heterogeneous systems]

Cons:-
Not good for large scale data
___________________________________________________________

4)EJB - Entity Bean


----------------
EJB- Enterprise Java Bean
3 types of EJB
Session Bean [only BL]
Entity Bean[persistence code]
Message Driven Bean[message passing]

Entity Bean has 2 types


BMP-BEan managed persistence [persistence code is written by programmer]
CMP-Container Managed Persistence [persistence code is autogenerated]

Pros:- Automated Object Persistence in database


[we dont need to connect to db,fire query]

Cons:-
i)developing EJB is overcomplex[need to implement specific interfaces]
ii)requires Managed Environment [requires Application Server]
iii)Not portable

Employee e=new Employee(....);


obj.save(e); --->table will be autogenerated/insert/data stored
___________________________________________________________

Simple as JDBC
Automated like SErialization,EJB
Pluggable like XML

Employee[POJO]--->empId,empName,empSal[POJO properties]
empdb--->eid,ename,esal

ORM - Object Relational Mapping


-------------------------------
refers to automated object persistence
of Java object into relational db
based on metadata that describes the mapping between
Java object & relational table

maps object to the relational db

advantages
1)Better System Architecture
2)Reduces Coding Time
3)Caching & Transaction mgt is inbuilt

ORM implementations
Hibernate,TopLink,EJB Entity Bean,IBatis/MyBatis
____________________________________________________

Hibernate
-----------
-Hibernate is a ORM framework which maps java object to relational db based on the
metadata we provide using xml/annotation

-open source
[go to the website--->download jar files free of cost]
http://www.hibernate.org

-developed by Gavin King

-non-invasive framework-POJO based[Plain Old Java Object]


POJO is a class which is not dependent any API,Architecture,Server.It is unit
testable & pluggable

-Hibernate can be used with any type of application


eg:-console,GUI,servlet,jsp,spring,struts

-Hibernate is purely used for persistence


__________________________________________________________

You might also like