title: Save hibernate object with foreign key without loading the dependent object
body: <p>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.</p>
  
  <p>Ex: Employee has a department foreign key, so if we need to save the employee object then we will do something like:</p>
  
  <pre><code>saveEmployee{
  emp.setName(name);
  Department department = session.find(Department.class,deptid);
  emp.setDepartment(department);
  }
  </code></pre>
  
  <p>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.</p>
  
  <p>Any better way to do this then
  <a href="https://stackoverflow.com/questions/2111294/is-it-possible-to-have-foreign-key-enforced-without-object-to-object-mapping">Is it possible to have foreign key enforced without object-to-object mapping?</a></p>