When we save an object in Hibernate then we save the dependent object not as an id but with loading that object and saving it.
Ex: Employee has a department foreign key, so if we need to save the employee object then we will do something like:
saveEmployee{
emp.setName(name);
Department department = session.find(Department.class,deptid);
emp.setDepartment(department);
}
Now in case we import 1000 records and there we have deptid as a separate column in excel, then unnecessary 1000 times db will be called to fetch respective department.
Any better way to do this then Is it possible to have foreign key enforced without object-to-object mapping?