As you contain learnt that in Hibernate, an entity will be created and persisted. Once the object has been transformed, it must be saved back to the database. This procedure continues until the next time the object is necessary, and it will be empty from the persistent store.
Thus an entity passes through different stages in its life cycle and Interceptor Interface provides methods which can be called at different stages to perform some optional tasks. These methods are call-backs from the session to the application, allowing the application to inspect and/or control properties of a persistent object before it is saved, updated, deleted or loaded. Following is the list of all the methods accessible within the Interceptor interface:
|S.N.||Method and Description|
Hibernate Interceptor gives us total manage over how an object will look to both the application and the database.
To accumulate an interceptor you can either perform Interceptor class straight or extend Empty Interceptor class. Following will be the easy steps to use Hibernate Interceptor functionality.
We will extend Empty Interceptor in our instance where Interceptor's method will be called manually when Employee object is formed and updated. You can apply more methods as per your requests.
Currently let us transform a little bit our first instance where we used EMPLOYEE table and Employee class to play with:
Second step would be creating tables in your database. There would be one table corresponding to each object you are willing to give persistence. Believe above matter need to be stored and retrieved into the following RDBMS table:
This step is to generate a mapping file that educate Hibernate how to map the define class or classes to the database tables.
In the end, we will create our application class with the main () method to sprint the application. Here it should be noted that while creating session object we used our Interceptor class as an quarrel.
Here are the steps to accumulate and run the above mentioned application. Create sure you have set PATH and CLASSPATH correctly before proceeding for the compilation and implementation.
You would get following consequence, and records would be formed in EMPLOYEE table.
If you prove your EMPLOYEE table, it should have following files:
Hibernate Related Interview Questions
|J2EE Interview Questions||Core Java Interview Questions|
|JSP Interview Questions||Java-Springs Interview Questions|
|Java Struts Interview Questions||Log4j Interview Questions|
|Software Development Lifecycle (SDLC) Interview Questions||NHibernate Interview Questions|
|Spring MVC Framework Interview Questions||Apache Struts 2 Interview Questions|
|Spring Aop Interview Questions|
All rights reserved © 2020 Wisdom IT Services India Pvt. Ltd
Wisdomjobs.com is one of the best job search sites in India.