When we save an object in Hibernate, we do not save the dependent object as an identifier, but when loading this object and saving it.
Ex: the employee has a department foreign key, so if we need to save the employee object, we will do something like:
saveEmployee{
emp.setName(name);
Department department = session.find(Department.class,deptid);
emp.setDepartment(department);
}
Now, if we import 1000 records, and there we have defit as a separate column in excel, then unnecessary 1000 times db will be called to get the corresponding department.
Any better way to do this, then
Is it possible to use a foreign key without binding the object to the object?
source
share