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:
It activate Hibernate Framework Configuration cfg=new Configuration(); It read both cfg file and mapping files cfg.configure();
SessionFactory:
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 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();
Transaction:
Transaction tx=session.beginTransaction(); tx.commit();
Query:
Criteria:
Flow of working during operation in Hibernate Framework: Suppose We want to insert an Object to the database. Here Object is nothing but persistence logic which we write on java program and create an object of that program. If we want to insert that object in the database or we want to retrieve the object from the database. Now the question is that how hibernate save the Object to the database or retrieve the object from the database. There are several layers through which Hibernate framework go to achieve the above task. Let us understand the layers/flow of Hibernate framework during performing operations: Stage I: In first stage, we will write the persistence logic to perform some specific operations to the database with the help of Hibernate Configuration file and Hibernate mapping file. And after that we create an object of the particular class on which we wrote the persistence logic. Stage II:In second stage, our class which contains the persistence logic will interact with the hibernate framework where hibernate framework gives some abstraction do perform some task. Now here the picture of java class is over. Now Hibernate is responsible to perform the persistence logic with the help of layers which is below of Hibernate framework or we can say that the layers which are the internal implementation of Hibernate. Stage III:In third stage, our hibernate framework interact which JDBC, JNDI, JTA etc to go to the database to perform that persistence logic. Stage IV & V:In fourth & fifth stage, hibernate is interact with Database with the help of JDBC driver. Now here hibernate perform that persistence logic which is nothing but CRUD operation. If our persistence logic is to retrieve an record then in the reverse order it will display on the console of our java program in terms of Object.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4