hi dma_k
it is not because of outer-join, i've add the outer-join="false" but got the same result and from genered sql i see no outer join.
hi steve
thanks for response
you HQL is the same as my 2nd query which is
from Test t where t.kname = 'SIZE' and t.Conecos.imp = 4
except the "select Test t"
i test your HQL but get the same result, here is the output:
Code:
Hibernate: select test0_.id as id, test0_.kname as kname0_, test0_.name as name0_ from public.test test0_, public.coneco conecos1_ where test0_.id=conecos1_.tid and test0_.kname='SIZE' and conecos1_.imp=4
Hibernate: select conecos0_.tid as tid1_, conecos0_.id as id1_, conecos0_.id as id0_, conecos0_.imp as imp1_0_, conecos0_.name as name1_0_, conecos0_.tid as tid1_0_ from public.coneco conecos0_ where conecos0_.tid=?
4 SIZE
4 Beta [4]
Hibernate: select conecos0_.tid as tid1_, conecos0_.id as id1_, conecos0_.id as id0_, conecos0_.imp as imp1_0_, conecos0_.name as name1_0_, conecos0_.tid as tid1_0_ from public.coneco conecos0_ where conecos0_.tid=?
3 SIZE
2 Alfa [4] 1 charli [3] 3 Delta [4]
3 SIZE
2 Alfa [4] 1 charli [3] 3 Delta [4]
i and a "name" column to the coneco table.
i noticed the generated sql which retrieve coneco(lazy loading) did not use imp = ? at all.
i use session filter to get what i need as following:
Test.hbm.xml:
Code:
<set name="Conecos" inverse="true">
<key>
<column name="tid" not-null="true" />
</key>
<one-to-many class="data.Coneco" />
<filter name="imp" condition=":imp = imp"/>
</set>
<filter-def name="imp">
<filter-param name="imp" type="int"/>
</filter-def>
and in java source:
Code:
session.enableFilter("imp").setParameter("imp", new Integer(4));
List list =session.createQuery("select t from Test t where t.kname = 'SIZE'").list();
for (Iterator iter = list.iterator(); iter.hasNext();) {
Test t = (Test) iter.next();
System.out.println(t);
}
with the filter on , the output of
select t from Test t where t.kname = 'SIZE'
is
Code:
Hibernate: select test0_.id as id, test0_.kname as kname0_, test0_.name as name0_ from public.test test0_ where test0_.kname='SIZE'
Hibernate: select conecos0_.tid as tid1_, conecos0_.id as id1_, conecos0_.id as id0_, conecos0_.imp as imp1_0_, conecos0_.name as name1_0_, conecos0_.tid as tid1_0_ from public.coneco conecos0_ where ? = conecos0_.imp and conecos0_.tid=?
3 SIZE
2 Alfa [4] 3 Delta [4]
Hibernate: select conecos0_.tid as tid1_, conecos0_.id as id1_, conecos0_.id as id0_, conecos0_.imp as imp1_0_, conecos0_.name as name1_0_, conecos0_.tid as tid1_0_ from public.coneco conecos0_ where ? = conecos0_.imp and conecos0_.tid=?
4 SIZE
4 Beta [4]
hibernate use ? = conecos0_.imp when retrieve Coneco so it got the right result.
since my team members come from strong sql background so they perfer to do things in HQL than java source.
so is there any way to do it in HQL?
thanks in advance