title: Hibernate Many-to-one lazy loading is not working
body: <p>I have a class and 2 many-to-one mappings in it , How can I lazy load them</p>
  
  <p>My properties</p>
  
  <pre><code>**teneo.mapping.also_map_as_class=true
  teneo.mapping.set_proxy=true
  teneo.mapping.mapping_file_name=/lazy.hbm.xml**
  </code></pre>
  
  <p>Mapping file ( lazy.hbm.xml)</p>
  
  <pre><code>&lt;class name="EnvironmentImpl" entity-name="**Environment**" abstract="false" lazy="true" discriminator-value="Environment" table="`ENVIRONMENT`" proxy="Environment"&gt;
      &lt;meta attribute="eclassName"&gt;Environment&lt;/meta&gt;
  
      &lt;property name="name" lazy="false" insert="true" update="true" not-null="true" unique="false" type="java.lang.String"&gt;
          &lt;column not-null="true" unique="false" name="`NAME`"/&gt;
      &lt;/property&gt;
  
      &lt;property name="description" lazy="false" insert="true" update="true" not-null="false" unique="false" type="java.lang.String"&gt;
          &lt;column not-null="false" unique="false" name="`DESCRIPTION`" length="512"/&gt;
      &lt;/property&gt;
  
      &lt;property name="contact" lazy="false" insert="true" update="true" not-null="false" unique="false" type="java.lang.String"&gt;
          &lt;column not-null="false" unique="false" name="`CONTACT`"/&gt;
      &lt;/property&gt;
  
      &lt;many-to-one  name="rootAppFolder" entity-name="ApplicationFolder" lazy="proxy" cascade="all" foreign-key="ENVIRONMENT_ROOTAPPFOLDER" insert="true" update="true" not-null="false" unique="true"&gt;
          &lt;column not-null="false" unique="false" name="`APPLICATINFLDER_RTAPPFOLDER_ID`"/&gt;
      &lt;/many-to-one&gt;
  
      &lt;many-to-one name="serviceVirtualization" entity-name="ServiceVirtualization" lazy="proxy" cascade="all" foreign-key="ENVIRNMENT_SERVICEVIRTALIZATIN" insert="true" update="true" not-null="false"&gt;
          &lt;column not-null="false" unique="false" name="`SRVCVRTLZTN_SRVICVIRTLIZTIN_ID`"/&gt;
      &lt;/many-to-one&gt;
  &lt;/class&gt;
  </code></pre>
  
  <p><code>As you can see class Environment has 2 many-to-one's with names</code> <code>ApplicationFolder and serviceVirtualization.</code></p>
  
  <pre><code>for a HQL query like -  from Environment where name = :name
  
  
      Which internally triggers 3 queries  
      Query1 : Environment ( this is right)
  
      Query2 : ApplicationFolder ( wrong.lazy loading should not.)
  
      Query 3 : serviceVirtualization ( wrong.lazy loading should not.)
  
  
  
              DEBUG - select environmen0_."NAME" as NAME4_31_, environmen0_."DESCRIPTION" as DESCRIPT5_31_, environmen0_."CONTACT" as CONTACT6_31_, environmen0_."APPLICATINFLDER_RTAPPFOLDER_ID" as APPLICAT7_31_, environmen0_."SRVCVRTLZTN_SRVICVIRTLIZTIN_ID" as SRVCVRTL8_31_ from "ENVIRONMENT" environmen0_ where environmen0_."NAME"=?
  
              DEBUG - select applicatio0_.e_id as e1_43_0_, applicatio0_.version_ as version3_43_0_, applicatio0_."NAME" as NAME4_43_0_, applicatio0_."ENVIRONMENT_ENV_E_ID" as ENVIRONM5_43_0_ as APPLICAT8_43_0_ from "APPLICATIONFOLDER" applicatio0_ where applicatio0_.e_id=?
  
              DEBUG - select servicevir0_.e_id as e1_35_0_, servicevir0_.version_ as version3_35_0_, servicevir0_.econtainer_class as econtainer4_35_0_, servicevir0_.e_container as e5_35_0_, servicevir0_.e_container_featureid as e6_35_0_ from "SERVICEVIRTUALIZATION" servicevir0_ where servicevir0_.e_id=?
  </code></pre>
  
  <p>What approaches I tried so far
  1) set lazy="no-proxy" , dont see any change in number of queries.</p>
  
  <p>2) setting not-found="exception".</p>
  
  <p>3)outer-join = "auto" </p>
  
  <p>Can any one suggest me a solution to reduce those 2 extra queries getting fired because of the eager many-to-one relations ?</p>
  
  <p>Please take a note of the foreign key relationships on many-to-one.</p>