|
Answer» The Hibernate architecture includes many OBJECTS such as persistent object, session factory, transaction factory, connection factory, session, transaction etc. Of these the more important ones are as below: - SessionFactory: The SessionFactory is a heavyweight object and is created when the application starts. It is created by providing it with the Configuration object which has the database configurations. If the application is using multiple databases, one SessionFactory object per database has to be created using a separate configuration file for each. The SessionFactory object configures the application using the configuration file and allows for Session object initiation. It is a THREAD-safe object and is used by all the threads of an application.
- Session: A session object is created when the application needs a physical connection with the database. It is a lightweight object and is instantiated each time the application interacts with the database. Persistent objects are saved and retrieved through a Session object. A Session object is not thread safe and THEREFORE should be created and destroyed as needed.
- Transaction: A Transaction means an operation, or a set of operations have been PERFORMED on the database. A transaction MANAGER monitors and handles the transactions. This is an optional object and the application may want to use their own application code for any database operations instead of using a Transaction. The org.hibernate.Transaction interface provides methods for transaction management.
|