Hello!
My question is simple: how to limit the "select" clause produced by Hibernate when you are making several join using sub-criteria (with the API createCriteria)?
Hibernate version: 3.1.3
Code between sessionFactory.openSession() and session.close():
You do something like that:
Code:
Criteria crit = session.createCriteria(MyMappedClass.class);
crit.createCriteria("myMappedProperty").
createCriteria("myMappedProperty2").
createCriteria("myMappedProperty3").
add(Restriction.eq("name","toto");
List result = crit.list();
To make it short, my problem is that I do multiple join using sub-criteria, so I broke the sql limit on column size... My code produce the following SQL:
Code:
select
this_.IDAGENT as IDAGENT6_3_,
this_.IDCOUNTRY as IDCOUNTRY6_3_,
this_.DMSPECIA as DMSPECIA6_3_,
this_.KDAGENT as KDAGENT6_3_,
this_.FNAGENT as FNAGENT6_3_,
this_.MIDNAGENT as MIDNAGENT6_3_,
this_.NMAGENT as NMAGENT6_3_,
this_.ADAGENT as ADAGENT6_3_,
this_.IDTOWN as IDTOWN6_3_,
this_.NMTOWN as NMTOWN6_3_,
this_.TELAGENT as TELAGENT6_3_,
this_.FAXAGENT as FAXAGENT6_3_,
this_.TLXAGENT as TLXAGENT6_3_,
this_.CTAGENT as CTAGENT6_3_,
this_.INFAGENT as INFAGENT6_3_,
this_.TITAGENT as TITAGENT6_3_,
this_.EMAILAGENT as EMAILAGENT6_3_,
this_.FREFAGENT as FREFAGENT6_3_,
this_.EPIDAGENT as EPIDAGENT6_3_,
this_.NATNBAGENT as NATNBAGENT6_3_,
inscriptio1_.ID as ID67_0_,
inscriptio1_.CREATOR_ID as CREATOR2_67_0_,
inscriptio1_.SENDER_ID as SENDER3_67_0_,
inscriptio1_.REPRESENTATIVE_ID as REPRESEN4_67_0_,
inscriptio1_.IDENTIFICATION_NUMBER as IDENTIFI5_67_0_,
inscriptio1_.CREATION_DATE as CREATION6_67_0_,
inscriptio1_.STATUS as STATUS67_0_,
inscriptio1_.COMMENT as COMMENT67_0_,
inscriptio1_.EXECUTION_REPORT as EXECUTION9_67_0_,
inscriptio1_.EXECUTION_DATE as EXECUTION10_67_0_,
owner3_.IDOWNER as IDOWNER93_1_,
owner3_.IDCOUNTRY as IDCOUNTRY93_1_,
owner3_.NATIONOWN as NATIONOWN93_1_,
owner3_.EPIDOWNER as EPIDOWNER93_1_,
owner3_.NTINCORP as NTINCORP93_1_,
owner3_.ORG as ORG93_1_,
owner3_.FNOWNER as FNOWNER93_1_,
owner3_.MIDNOWNER as MIDNOWNER93_1_,
owner3_.NMOWNER as NMOWNER93_1_,
owner3_.SNMOWNER as SNMOWNER93_1_,
owner3_.ADOWNER as ADOWNER93_1_,
owner3_.IDTOWN as IDTOWN93_1_,
owner3_.NMTOWN as NMTOWN93_1_,
owner3_.NMSTATE as NMSTATE93_1_,
owner3_.TELOWNER as TELOWNER93_1_,
owner3_.FAXOWNER as FAXOWNER93_1_,
owner3_.TLXOWNER as TLXOWNER93_1_,
owner3_.CTOWNER as CTOWNER93_1_,
owner3_.INFOWNER as INFOWNER93_1_,
owner3_.UNMOWNER as UNMOWNER93_1_,
owner3_.PAYCAT as PAYCAT93_1_,
owner3_.TITOWNER as TITOWNER93_1_,
owner3_.EMAILOWNER as EMAILOWNER93_1_,
owner3_.FREFOWNER as FREFOWNER93_1_,
owner3_.NATNBOWNER as NATNBOWNER93_1_,
inscriptio2_.ID as ID70_2_,
inscriptio2_.INSCRIPTION_TYPE_ID as INSCRIPT2_70_2_,
inscriptio2_.INSCRIPTION_ID as INSCRIPT3_70_2_,
inscriptio2_.NUMBER as NUMBER70_2_,
inscriptio2_.COMMENT as COMMENT70_2_
from
SOPRANO.AGENT this_,
SOPRANO.INSCRIPTION inscriptio1_,
SOPRANO.OWNER owner3_,
SOPRANO.INSCRIPTION_TYPES_IN_INSCRIPTION inscriptio2_
where
this_.IDAGENT=inscriptio1_.REPRESENTATIVE_ID
and inscriptio1_.SENDER_ID=owner3_.IDOWNER
and inscriptio1_.ID=inscriptio2_.INSCRIPTION_ID
and inscriptio2_.COMMENT like ?
and owner3_.NMOWNER like ?
order by
this_.NMAGENT asc
but actually, I only need some thing like:
Code:
select
this_.IDAGENT as IDAGENT6_3_,
this_.IDCOUNTRY as IDCOUNTRY6_3_,
this_.DMSPECIA as DMSPECIA6_3_,
this_.KDAGENT as KDAGENT6_3_,
this_.FNAGENT as FNAGENT6_3_,
this_.MIDNAGENT as MIDNAGENT6_3_,
this_.NMAGENT as NMAGENT6_3_,
this_.ADAGENT as ADAGENT6_3_,
this_.IDTOWN as IDTOWN6_3_,
this_.NMTOWN as NMTOWN6_3_,
this_.TELAGENT as TELAGENT6_3_,
this_.FAXAGENT as FAXAGENT6_3_,
this_.TLXAGENT as TLXAGENT6_3_,
this_.CTAGENT as CTAGENT6_3_,
this_.INFAGENT as INFAGENT6_3_,
this_.TITAGENT as TITAGENT6_3_,
this_.EMAILAGENT as EMAILAGENT6_3_,
this_.FREFAGENT as FREFAGENT6_3_,
this_.EPIDAGENT as EPIDAGENT6_3_,
this_.NATNBAGENT as NATNBAGENT6_3_
from
SOPRANO.AGENT this_,
SOPRANO.INSCRIPTION inscriptio1_,
SOPRANO.OWNER owner3_,
SOPRANO.INSCRIPTION_TYPES_IN_INSCRIPTION inscriptio2_
where
this_.IDAGENT=inscriptio1_.REPRESENTATIVE_ID
and inscriptio1_.SENDER_ID=owner3_.IDOWNER
and inscriptio1_.ID=inscriptio2_.INSCRIPTION_ID
and inscriptio2_.COMMENT like ?
and owner3_.NMOWNER like ?
order by
this_.NMAGENT asc
- I found
Projections to limit the select part to something like "this_.*", but how can I get in the result list to be a list of 'MyMappedClass'.
- Other hint is
tranformers, with AliasToEntityMapResultTransformer, but it seems that it is not implemented (still need to update my source, but can't find it in 3.2.4 source)
Thanks for reading, and thank you in advance for you advice!
Regards,
Yoann.
(HQL is not a solution that fit my needs)