Quote:
if you use createCriteria()
http://www.hibernate.org/hib_docs/v3/ap ... ang.String)
it will create a join, but it will not include the columns of the joined table in the result.
Thank's but it seems not working for me
Here's my example
Code:
Criteria crit = hibernateTemplate.getSessionFactory().getCurrentSession().createCriteria(Candidature.class,"candidature");
crit.setResultTransformer(Criteria.ROOT_ENTITY);
crit.createCriteria("campagne").add(Restrictions.like("reference", "%CG%"));
List<Candidature> resultat = crit.list();
OK, my result contains Candidature BUT the generated SQL is
Code:
select this_.CDT_ID, all my columns for Candidature.class [...],
campagne1_.CMP_ID as CMP1_2_0_, all the colum ofcampagne that i don't want !
from candidatures this_ inner join campagnes campagne1_ on this_.CMP_ID=campagne1_.CMP_ID
where campagne1_.CMP_REFERENCE like ?
And it's bad because of performance issue, I don't want all the colum of the Campagne table to be return as I don't need them !
What I need is something that works in HQL
select candidature from Candidature candidature join candidature.campagne campagne where campagne.reference like :ref
But I have to use the Criteria API because of dynamic restrictions...
Thanks for you answer
Hibernate version 3.2.6GA