SessionFactory
SessionFactory is a factory class developed on factory design pattern, to get a session object.
its responsibility is to read hibernate configuration class,
connect to database and
create sesson object.
Session
Core interface use to perform database operation,
life cycle of a session is bound by begining and end transaction.
Difference between currentSession() and openSession()
currentSession is to get the current session object.
we dont need to close it.
it belongs to hibernate context. once sessionfactory gets closed the session object close.
opensession is to open a new session.
we need to manually close after the operation.
Difference between get() and load()
get method loads data as soon as it is called.
load method returns a proxy object when ever it called. a lazy loading process
What are the patterns used in hibernate ?
1. Domain model pattern
2. Factory pattern - example SessionFactory class
3. Proxy pattern -
4. Data Mapper -
Second level cache ( EH Cache)
dependency : hibernate-ehcache
class : EhCacheRegionFactory
Separate ehcache.xml file where we give details like diskstore path, time to live etc
@cache annotation has to be used in entity class
Immutable class in java
“Hope is important because it can make the present moment less difficult to bear. If we believe that tomorrow will be better, we can bear a hardship today.”
No comments:
Post a Comment
Your feedback may help others !!!