title: Hibernate change fetch mode in runtime
body: <p>I have two tables related together using one-to-many relation :
    employee -> department : and relation through department_id in the employee table.</p>
  
  <p>I use hibernate : and my hibernate mapping files are:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
                                     "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"&gt;
  &lt;!-- 
      Mapping file autogenerated by MyEclipse Persistence Tools
  --&gt;
  &lt;hibernate-mapping default-lazy="false"&gt;
   &lt;class catalog="moi"
    name="com.ebla.moi.correspondence.model.entity.user.User" table="user"&gt;
    &lt;id name="id" type="java.lang.Long"&gt;
     &lt;column name="id"/&gt;
     &lt;generator class="identity"/&gt;
    &lt;/id&gt;
    &lt;many-to-one
     class="com.ebla.moi.correspondence.model.entity.department.Department"
     fetch="select" name="department"&gt;
     &lt;column name="department_id"/&gt;
    &lt;/many-to-one&gt;
    &lt;property generated="never" lazy="false" name="name" type="java.lang.String"&gt;
     &lt;column length="128" name="name" not-null="true"/&gt;
    &lt;/property&gt;
    &lt;property generated="never" lazy="false" name="email" type="java.lang.String"&gt;
     &lt;column length="128" name="email" not-null="true" unique="true"/&gt;
    &lt;/property&gt;
    &lt;property generated="never" lazy="false" name="maritalStatus" type="java.lang.Short"&gt;
     &lt;column name="marital_status" not-null="true"/&gt;
    &lt;/property&gt;
    &lt;property generated="never" lazy="false" name="hireDate" type="java.lang.String"&gt;
     &lt;column length="64" name="hire_date"/&gt;
    &lt;/property&gt;
   &lt;/class&gt;
  &lt;/hibernate-mapping&gt;
  </code></pre>
  
  <p>and the second mapping file is : </p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
                                     "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"&gt;
  &lt;!-- 
      Mapping file autogenerated by MyEclipse Persistence Tools
  --&gt;
  &lt;hibernate-mapping default-lazy="false"&gt;
   &lt;class catalog="moi"
    name="com.ebla.moi.correspondence.model.entity.department.Department" table="department"&gt;
    &lt;id name="id" type="java.lang.Long"&gt;
     &lt;column name="id"/&gt;
     &lt;generator class="identity"/&gt;
    &lt;/id&gt;
    &lt;property generated="never" lazy="false" name="name" type="java.lang.String"&gt;
     &lt;column length="256" name="name" unique="true"/&gt;
    &lt;/property&gt;
    &lt;set inverse="true" name="users" sort="unsorted"&gt;
     &lt;key&gt;
      &lt;column name="department_id"/&gt;
     &lt;/key&gt;
     &lt;one-to-many class="com.ebla.moi.correspondence.model.entity.user.User"/&gt;
    &lt;/set&gt;
   &lt;/class&gt;
  &lt;/hibernate-mapping&gt;
  </code></pre>
  
  <p>My problem is : sometimes i need to get the employee with his department, and other times i need only the employee information with out department information..... and the same thing with department with employee.... using the mapping file above the hibernate bring the department and it's users if i need the employee or not... how to define my needs to hibernate to fetch just what i need...</p>
  
  <p>thank you</p>