Hibernate Document
Hibernate Document
Advantages of ORM:
Reduce the repeatable code.
I t provides portability, we can shift 1DBto another DB easily.
Less development time.
Maintainability easy, because less code.
Hibernate uses Cache Mechanism
In Hibernate we can write HQL (Hibernate Query Language)
Hibernate using Lazy loading to improve the performance
Hibernate using Batch Updates to improve the performance
Create tables automatically
Generates Key Automatically
**
savel)
evictu
******************s ersist()
session.closel)
new
saveOrUpdate)
*************
Session
lock
deletel) update
mergel)
saveOrUpdate
*******************
Beu
load)
HaL query
* * * * * * * * * * * * * * * * * *
Hibernate Connection:
Configuration
Transaction
Session Factory
Session
Query or Criteria
Persist():
Return type is void
>It doesn't return any ID, because return type is void.
I t will work within the boundary only
I t supports both Hibernate and JPA
I t will take less time to execute
Savel):
I t l create always new record in Database.
I t brings Object Transient state to Persistent State
SaveOrUpdatel):
i f already record is available with ID it 'l update the record.
I f record is not available with 1D, it inserts new record into DB.
I t brings Object Transient To persistent To detached state.
Evict():
Evict() method can remove single objectfrom the session
Clear():
Clear() method will remove entire session Object
Closel):
Close the session by calling Session.close() method
Differences betweenload()and get()?
Load():
If Object is not available with given id it throws
ObjectNotFoundException
It always return Proxy(Dummy) Object, so this method is Lazy loading
i t is slightly faster than get method
i f you are sure that ID object is exist you can use load()
Example: songs, or movie trailer
get():
What is Cache?
I f you want to fetch the records from the database,
If you fire same request multiple times it has to fetch the data from
database again and again.
I t needs to travel the request from Client-> Application -> Database
So, itwillimpact on application performance.
When we fired same request again and again, instead of fetching the
data from database again and again, we can maintain Cache to store the
data.
For the first time it will fetch the data from database and it 1l stores in
Cache memory.
While fetching the same data for the 2r time onwards it 1l fetch the
data from the Cache, the request no needs to travel till Database.
Note
W e can enable Second Level Cache with EHCache or OSCache or
WarmCache or JBossCache