We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as ODT, PDF, TXT or read online on Scribd
You are on page 1/ 2
Hibernate Architecture
Last Updated : 14 Aug, 2024
Prerequisites: Introduction of Hibernate
Hibernate is a framework which is used to develop persistence logic which is independent of Database software. In JDBC to develop persistence logic we deal with primitive types. Whereas Hibernate framework we use Objects to develop persistence logic which are
independent of database software. Hibernate Architecture:
Configuration: • Configuration is a class which is present in org.hibernate.cfg package. It activates Hibernate framework. It reads both configuration file and mapping files. It activate Hibernate Framework Configuration cfg=new Configuration(); It read both cfg file and mapping files cfg.configure(); • It checks whether the config file is syntactically correct or not. • If the config file is not valid then it will throw an exception. If it is valid then it creates a meta-data in memory and returns the meta- data to object to represent the config file. SessionFactory: • SessionFactory is an Interface which is present in org.hibernate package and it is used to create Session Object. • It is immutable and thread-safe in nature. buildSessionFactory() method gathers the meta-data which is in the cfg Object. From cfg object it takes the JDBC information and create a JDBC Connection. SessionFactory factory=cfg.buildSessionFactory(); Session: • Session is an interface which is present in org.hibernate package. Session object is created based upon SessionFactory object i.e. factory. • It opens the Connection/Session with Database software through Hibernate Framework. • It is a light-weight object and it is not thread-safe. • Session object is used to perform CRUD operations. Session session = factory.openSession(); openSession() is a method provided by the SessionFactory that creates and returns a new Session instance. This session is not bound to any transaction or context and is independent of any ongoing transactions in the application. We can also use getCurrentSession, that returns a Session bound to the current context, which is usually managed by a transaction manager or a framework like Spring. Session session = sessionFactory.getCurrentSession();