Configuration or AnnotationConfiguration :
- These are available in org.hibernate.cfg package. This is the first class that will be instantiated by hibernate application.
- You can use Configuration or AnnotationConfiguration class object for 2 task :
-> calling configure or configure(String) method.
-> calling buildSessionFactory() method. - configure() method is responsible for :
-> reading the data from hibernate configuration document.
-> reading the data from all the hibernate mapping documents specified in configuration document. - buildSessionFactory() is responsible for creating SessionFactory object.
- Configuration or annotation configuration object is single threaded and short lived.
- Once SessionFactory object is created then there is no use with Configuration or AnnotationConfiguration object.
- This interface is available in org.hibernate package.
- SessionFactory object is Multi-Threadded and long lived.
- When you call buildSessioFactory() method on Configuration object then following task will happen.
-> set the default to many parameters like batch, size fetch size etc.
-> generate and catches the sql queries required.
-> select the Connection provider
-> select the TransactionFactory. - SessionFactory is :
-> factory of Session object.
-> client for connection provider.
-> client for TransactionFactory. - You need to create one SessionFactory per database.
- when you are using multiple databases then you need to write multiple hibernate configuration docs.
- This is an interface available in org.hibernate package.
- Session object is single threaded and short lived.
- Session represents period of time where user can do multiple database operation.
- Session Object :
-> uses TransactionFactory to get the transaction.
-> get the connection from ConnectionProvider.
- When transaction is started the following task will happen.
-> session cache will be created
-> connection will be taken and will be associated with the current session. - While transaction is running following task will happen.
-> when any object is participated in session operations, that will be placed in session cache. - When transaction is committed the following task will happen :
-> session will be flushed(here the synchronization of persistent data with the database will be performed)
-> session cache will be destroyed
-> commit will be issued to database
-> connection will be released
Read about Hibernate Architecture at Click Here
ReplyDelete