title: Hibernate lazy loading not work with many-to-one mapping
body: <p>I have problem of performance in my many-to-one mapping. When I debug the SQL query in log file the principal query it's ok, but after i have other query representing many-to-one object mapping.</p>
  
  <p>Entity.hbm.xml :</p>
  
  <pre><code>&lt;?xml version="1.0"?&gt;
  &lt;!DOCTYPE hibernate-mapping PUBLIC
      "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
      "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" &gt;
  
  &lt;hibernate-mapping&gt;
      &lt;class name="com.omb.database.mapping.MyEntity" table="MY_ENTITY"&gt;
          &lt;id name="id" type="java.lang.Integer"&gt;
              &lt;column name="ENTITY_ID"/&gt;
              &lt;generator class="sequence"&gt;
                  &lt;param name="sequence"&gt;SEQ_MY_ENTITY&lt;/param&gt;
              &lt;/generator&gt;
          &lt;/id&gt;
  
          &lt;property name="prop1" type="string" column="PROP1" /&gt;
          &lt;many-to-one name="object1" column="OBJECT1_ID" class="com.omb.database.mapping.Object1" /&gt;
          &lt;many-to-one name="object2" column="OBJECT2_ID" class="com.omb.database.mapping.Object2" /&gt; 
  
      &lt;/class&gt;
  &lt;/hibernate-mapping&gt;
  </code></pre>
  
  <p>Object1.hbm.xml :</p>
  
  <pre><code>&lt;?xml version="1.0"?&gt;
  &lt;!DOCTYPE hibernate-mapping PUBLIC
      "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
      "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" &gt;
  
  &lt;hibernate-mapping default-lazy="true"&gt;
  
      &lt;class name="com.omb.database.mapping.Object1" table="TABLE_OBJECT_1"&gt;
          &lt;id name="id" type="java.lang.Integer" column="OBJECT1_ID" /&gt;
          &lt;property name="label" type="string" column="LABEL_OBJECT_1" length="15" /&gt;
      &lt;/class&gt;
  
  &lt;/hibernate-mapping&gt;
  </code></pre>
  
  <p>Object2.hbm.xml :</p>
  
  <pre><code>&lt;?xml version="1.0"?&gt;
  &lt;!DOCTYPE hibernate-mapping PUBLIC
      "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
      "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" &gt;
  
  &lt;hibernate-mapping default-lazy="true"&gt;
  
      &lt;class name="com.omb.database.mapping.Object2" table="TABLE_OBJECT_2"&gt;
          &lt;id name="id" type="java.lang.Integer" column="OBJECT2_ID" /&gt;
          &lt;property name="label" type="string" column="LABEL_OBJECT_2" length="15" /&gt;
      &lt;/class&gt;
  
  &lt;/hibernate-mapping&gt;
  </code></pre>
  
  <p>Query HBM :</p>
  
  <pre><code>public List&lt;Entity&gt; findByObject1Id(Integer object1Id) throws DataAccesException {
  
          List&lt;Entity&gt; results = null;
          try {
              Query query = this.getSession().createQuery(
                      "from Entity ent where ent.object1.id = :object1Id");
              query.setParameter("object1Id", object1Id);
              results = query.list();
          } catch (HibernateException hbe) {
              throw new DataAccesException(hbe);
          }
  
          return results;
      }
  </code></pre>
  
  <p>in pom.xml </p>
  
  <pre><code>&lt;!-- Hibernate 3 --&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.hibernate&lt;/groupId&gt;
              &lt;artifactId&gt;hibernate&lt;/artifactId&gt;
              &lt;version&gt;3.2.6.ga&lt;/version&gt;
              &lt;exclusions&gt;
                  &lt;exclusion&gt;
                      &lt;groupId&gt;javax.transaction&lt;/groupId&gt;
                      &lt;artifactId&gt;jta&lt;/artifactId&gt;
                  &lt;/exclusion&gt;
                  &lt;exclusion&gt;
                      &lt;groupId&gt;net.sf.ehcache&lt;/groupId&gt;
                      &lt;artifactId&gt;ehcache&lt;/artifactId&gt;
                  &lt;/exclusion&gt;
                  &lt;exclusion&gt;
                      &lt;groupId&gt;asm&lt;/groupId&gt;
                      &lt;artifactId&gt;asm-attrs&lt;/artifactId&gt;
                  &lt;/exclusion&gt;
              &lt;/exclusions&gt;
          &lt;/dependency&gt;
  </code></pre>