Synchronization Between Object and Database Table Rows
Posted By : Amarjeet Kumar | 09-Dec-2018
It basically describes the synchronization between Java objects and Database tables and How the Hibernate Framework handles all this synchronization process.
Synchronization
- If the modification done in objects are reflecting to table rows and vice-versa then it is called synchronization. Hibernate framework takes care of this synchronization by taking the support of JDBC code and SQL queries internally.
- Every Java object is identified by JVM through hashcode, similarly, every object of domain class will be identified by the Hibernate through identity value or identifier value. This value is generated based on the identifier field or property configuration done in the mapping file. We configure one or other property of domain class as identifier field or identity field.
- Hibernate framework generates "Update" query having domain class object identifier value as the criteria value to synchronize the changes done in the object to the database table row. Similarly, it generates "Select" query having identifier value as criteria value to synchronize changes done in a Database table row to object.
- Using o-r mapping to map more java classes of Java Application with more Database tables of Database software and we can go for objects based Database software independent persistence logic development without using any SQL Queries. This also makes the o-r mapping persistence logic as portable persistence logic across the multiple Database Softwares.
Example
Java Class
public class Customer{
private int id;
private String name;
private String street;
private String city:
private String country;
..................................//setters and getters
........................................
}
O-R mapping configurations
Customer(class)<---------------------------->Customer_tab(DB table)
id<----------------------->cid
name<------------------->cname
street<------------------>cstreet
city<--------------------->ccity
country<-------------->ccountry
Summary
This post mainly focused on the relationship between Java objects and how the changes are done in Java object reflects the database table and vice-versa.
Reference
- https://hibernate.org/orm/documentation/5.3/
- https://www.google.co.in/imghp?hl=en&authuser=0
Cookies are important to the proper functioning of a site. To improve your experience, we use cookies to remember log-in details and provide secure log-in, collect statistics to optimize site functionality, and deliver content tailored to your interests. Click Agree and Proceed to accept cookies and go directly to the site or click on View Cookie Settings to see detailed descriptions of the types of cookies and choose whether to accept certain cookies while on the site.
About Author
Amarjeet Kumar
He is working as Associate Consultant-Development on BlockChain Project.