title: Conditional part of a hibernate query
body: <p>this is a simplification of a complex query.</p>
  
  <p>I want to retrieve the details of a concrete event-new (with a known passed idNew).</p>
  
  <p>The problem is that I don't know how to tell to the hibernate sql engine that I want to retrieve the fields of that record, independently on how that new <strong>has or not</strong> an associated file.</p>
  
  <p>I don't know how to write the conexion with the last clause (and newsWfLocalFiles.idNewsWfLocal = newsWfLocal.idNewsWfLocal)</p>
  
  <pre><code>Query query = this.sessionFactory.getCurrentSession().createQuery(
      "select news.idNews, newsWfLocal.title, newsWf.date, newsWfLocalFiles.url" +
      " from News news, NewsWf newsWf, NewsWfLocal newsWfLocal, NewsWfLocalFiles newsWfLocalFiles" +
      " where news.idNews = :idNews" +
      " and newsWf.news.idNews = news.idNews" +
      " and newsWf.idNewsWf = newsWfLocal.idNewsWf" +
      " and newsWfLocal.idLocal = 1" +
      " and newsWfLocalFiles.idNewsWfLocal = newsWfLocal.idNewsWfLocal");
  </code></pre>
  
  <p>I suppose that the key is to build the <strong>form</strong> sentence properly, but I cant figure out how to do that.</p>
  
  <p>These are the relationships between tables:</p>
  
  <p>News one-to-many NewsWf</p>
  
  <p>NewsWf one-to-many NewsWfLocal </p>
  
  <p>NewsWfLocal one-to-one NewsWfLocalFiles</p>
  
  <p>With the next form clause I feel I am near the solution, but the retrieved 'localFile' is still null, although in the cases that field is not empty:</p>
  
  <pre><code>from News news join news.newsWfs newsWfs join newsWfs.newsWfsLocal newsWfsLocal left outer join newsWfsLocal.newsWfLocalFiles newsWfLocalFiles
  </code></pre>
  
  <p>Here the details of the one-to-one mappings:</p>
  
  <p>in <strong>NewsWfLocal.xml</strong>:</p>
  
  <pre><code>&lt;one-to-one name="newsWfLocalFiles" class="com.sample.mdl.NewsWfLocalFiles" fetch="select" lazy="false" &gt;&lt;/one-to-one&gt;
  </code></pre>
  
  <p>in <strong>NewsWfLocalFiles.xml</strong>:</p>
  
  <pre><code>&lt;one-to-one name="newsWfLocal" class="com.sample.mdl.NewsWfLocal" fetch="select" lazy="false"&gt;&lt;/one-to-one&gt;
  </code></pre>