this is a simplification of a complex query.
I want to retrieve the details of a concrete event-new (with a known passed idNew).
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 has or not an associated file.
I don't know how to write the conexion with the last clause (and newsWfLocalFiles.idNewsWfLocal = newsWfLocal.idNewsWfLocal)
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");
I suppose that the key is to build the form sentence properly, but I cant figure out how to do that.
These are the relationships between tables:
News one-to-many NewsWf
NewsWf one-to-many NewsWfLocal
NewsWfLocal one-to-one NewsWfLocalFiles
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:
from News news join news.newsWfs newsWfs join newsWfs.newsWfsLocal newsWfsLocal left outer join newsWfsLocal.newsWfLocalFiles newsWfLocalFiles
Here the details of the one-to-one mappings:
in NewsWfLocal.xml:
<one-to-one name="newsWfLocalFiles" class="com.sample.mdl.NewsWfLocalFiles" fetch="select" lazy="false" ></one-to-one>
in NewsWfLocalFiles.xml:
<one-to-one name="newsWfLocal" class="com.sample.mdl.NewsWfLocal" fetch="select" lazy="false"></one-to-one>